http/http_response_handler
library
Classes
-
JsonBytes
-
A JSON body that is already encoded, so it is not encoded twice
(
ETag hashes the bytes first). For internal use.
-
TextBytes
-
A text body that is already UTF-8 (
DoxResponse.contentBytes). It is
sent as it is, with the content type of the response. For internal
use.
Functions
-
answerStarted(HttpResponse res)
→ bool
-
true when the answer of
req is already started or ended by its
handler: the head is sent or the response is closed
-
encodeJson(dynamic payload)
→ List<int>
-
payload as JSON bytes, like the response sends it
-
endResponse(HttpResponse res)
→ void
-
Sends
res when nothing waits for it. The native server sends with no
Future: the Future of close() would only keep the request alive until
its microtask runs, and under load the heap grows. A dart:io
response is closed as before. Errors go to res.done, as with an
unused close().
-
headSent(HttpResponse res)
→ bool
-
true when the head of
res already went out (a flush or a streamed
body). Then the status and headers are fixed and the body is running.
Needs a server that tells it: NativeResponse.headSent or
DoxHttpResponse.headSent.
-
htmlForText(HttpResponse res)
→ void
-
With
CoreFlags.htmlStrings, a string is sent as text/html. Only
when the type is still the preset one: a type set by a middleware or
the controller stays. The preset can not be told from ContentType.text
set by hand, so use response(text).contentType(...) to keep plain
text.
-
httpResponseHandler(dynamic payload, HttpRequest request)
→ dynamic
-
-
releaseTakeOver(HttpRequest req)
→ void
-
the handler took over, but never started the answer (it threw first).
Dox answers for it, so the client does not wait for a timeout.
-
responseDataHandler(dynamic payload, HttpRequest request)
→ void
-
Handle response for different types of data
such as string, stream, file, Model, List, encodable.
-
responseTakenOver(HttpRequest req)
→ bool
-
true when the handler of
req took over its answer
-
sendStaticFile(HttpRequest request, File file, int length, [ServerFile? opened])
→ void
-
Sends
file, a file of Route.staticFiles with length bytes (from
its stat), like a File that a controller returns. It does not ask
the disk for the size again.
-
showErrors()
→ bool
-
True when
APP_ENV is development or local. Then error text may
be sent to the client. Dox uses this rule for its own error answers.
Use it when your code sends errors itself, so it follows the same rule.
-
the value of header
name, or null when it is missing or sent more
than once. HttpHeaders.value throws (a 500) on a repeated header.
-
takeOverResponse(HttpRequest req)
→ void
-
Dox sends nothing more for
req: its handler owns the answer. See
DoxRequest.takeOverResponse.
-
utf8Bytes(String text)
→ Uint8List
-
text as UTF-8 bytes. Same bytes as utf8.encode. An ASCII text is
written straight into a list of the right size. utf8.encode first
makes a list 3 times the text length, then copies the used part.