Class HttpServer.Response
- Enclosing class:
HttpServer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpServer.ResponseA response with headers but no body, for 304 and for HEAD.static HttpServer.ResponseA response whose body is a file.intstatic HttpServer.Responsestatic HttpServer.ResponseA JSON response serialised straight into the connection's write buffer.static HttpServer.Response
-
Constructor Details
-
Response
-
Response
A body AND application headers, which nothing public could express.
The constructor above always passed null for them, empty() takes headers but discards the body, and file() wants a descriptor -- so a handler returning JSON with a Set-Cookie, a CORS header or a cache directive had no supported way to say so, even though both protocol writers send extra headers. Server-owned names are still refused at write time.
-
-
Method Details
-
file
public static HttpServer.Response file(int status, String contentType, int fd, long offset, long length, Map extraHeaders) A response whose body is a file. The server sends it with sendfile where the platform has it, so the bytes never enter user space, and CLOSES the descriptor when it is done -- a handler that returned one must not. -
text
-
json
-
jsonValue
A JSON response serialised straight into the connection's write buffer.
Prefer this to json(status, Json.write(value)): that builds a StringBuilder, grows its char[], copies it into a String and encodes that to bytes, for a document about to go to a socket and be discarded. Deliberately a DIFFERENT NAME rather than an overload taking Object -- an overload would bind a String-typed variable to this method and double-encode it, which is exactly the kind of thing that is found in production rather than in review.
-
empty
A response with headers but no body, for 304 and for HEAD. -
getStatus
public int getStatus()
-