Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public static final class HttpServer.Response
- Object
- HttpServer.Response
Constructors
public Response(int status, String contentType, byte[] body) | |
public Response(int status, String contentType, byte[] body, Map extraHeaders) | A body AND application headers, which nothing public could express. |
Methods
Inherited methods
Constructor details
Response
public Response(int status, String contentType, byte[] body)Response
public Response(int status, String contentType, byte[] body, Map extraHeaders)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
stream
public static HttpServer.Response stream(int status, String contentType, HttpServer.BodyWriter writer)file
public static HttpServer.Response file(int status, String contentType, int fd, long offset, long length, Map extraHeaders)text
public static HttpServer.Response text(int status, String body)json
public static HttpServer.Response json(int status, String body)jsonValue
public static HttpServer.Response jsonValue(int status, Object value)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
public static HttpServer.Response empty(int status, String contentType, Map extraHeaders)getStatus
public int getStatus()header
public HttpServer.Response header(String name, String value)