1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-02-10 20:41:37 +02:00

[#5940] added blob response write helper

This commit is contained in:
Gani Georgiev 2024-11-25 09:11:13 +02:00
parent 8f6e91c485
commit 5a5211d7f2
4 changed files with 6271 additions and 6232 deletions

View File

@ -1,3 +1,8 @@
## v0.23.1 (WIP)
- Added `RequestEvent.Blob(status, contentType string, bytes)` response write helper ([#5940](https://github.com/pocketbase/pocketbase/discussions/5940)).
## v0.23.0
> [!NOTE]

File diff suppressed because it is too large Load Diff

View File

@ -221,6 +221,14 @@ func (e *Event) Stream(status int, contentType string, reader io.Reader) error {
return err
}
// Blob writes a blob (bytes slice) response.
func (e *Event) Blob(status int, contentType string, b []byte) error {
e.setResponseHeaderIfEmpty(headerContentType, contentType)
e.Response.WriteHeader(status)
_, err := e.Response.Write(b)
return err
}
// FileFS serves the specified filename from fsys.
//
// It is similar to [echo.FileFS] for consistency with earlier versions.

View File

@ -500,6 +500,26 @@ func TestEventStream(t *testing.T) {
}
}
func TestEventBlob(t *testing.T) {
scenarios := []testResponseWriteScenario[[]byte]{
{
name: "blob",
status: 234,
headers: map[string]string{"content-type": "text/test"},
body: []byte("test"),
expectedStatus: 234,
expectedHeaders: map[string]string{"content-type": "text/test"},
expectedBody: "test",
},
}
for _, s := range scenarios {
testEventResponseWrite(t, s, func(e *router.Event) error {
return e.Blob(s.status, s.headers["content-type"], s.body)
})
}
}
func TestEventNoContent(t *testing.T) {
s := testResponseWriteScenario[any]{
name: "no content",