[#5940] added blob response write helper
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user