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:
parent
8f6e91c485
commit
5a5211d7f2
@ -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]
|
||||
|
12470
plugins/jsvm/internal/types/generated/types.d.ts
vendored
12470
plugins/jsvm/internal/types/generated/types.d.ts
vendored
File diff suppressed because it is too large
Load Diff
@ -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.
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user