Response
Spry's response object is the HttpResponse
object from dart:io
. We assume that you are already familiar with it. If you are not familiar with it, you can check out dart:io → HTTP Response documentation.
Throughout the request cycle, Response has no special magic, because in the design of dart:io
, HttpResponse
is based on IOSink
, which is good enough to use!
But IOSonk
has a defective design, that is, we don’t know when IOSink
has been closed. So we added an isClosed
attribute to HttpResponse
to determine whether IOSink
has been closed.
if (!response.isClosed) {
response.write("Hello World!");
}
It is very useful for post-post middleware. We can determine whether it has been closed to avoid exceptions caused by writing input when it is closed.
DANGER
Please note that in the response design in dart:io
, the headers operation must be performed before writing the body data, otherwise an exception will be thrown.
Once you start writing body data, the headers will be locked and you will not be able to modify the headers again.
We recommend that you use
Responsible
to return data, which will automatically handle these problems for you.