Module jls.net.http.HttpExchange
The HttpExchange class wraps the HTTP request and response.
Class HttpExchange
httpExchange:getContext () | Returns the HTTP context. |
httpExchange:getRequest () | Returns the HTTP request. |
httpExchange:getResponse () | Returns the HTTP response. |
httpExchange:getRequestMethod () | Returns the HTTP request method. |
httpExchange:getRequestHeaders () | Returns the HTTP request headers. |
httpExchange:getRequestArguments () | Returns the captured values of the request target path using the context path. |
httpExchange:onRequestBody ([buffer]) | Returns a promise that resolves once the request body is available. |
httpExchange:onClose () | Returns a promise that resolves once the exchange is closed. |
httpExchange:setResponseStatusCode (statusCode[, reasonPhrase[, body]]) | Sets the status code for the response. |
HttpExchange.ok (httpExchange[, body[, contentType]]) | Updates the response with the OK status code, 200. |
HttpExchange.badRequest (httpExchange[, reasonPhrase]) | Updates the response with the status code Bad Request, 400. |
HttpExchange.forbidden (httpExchange[, reasonPhrase]) | Updates the response with the status code Forbidden, 403. |
HttpExchange.notFound (httpExchange) | Updates the response with the status code Not Found, 404. |
HttpExchange.methodNotAllowed (httpExchange) | Updates the response with the status code Method Not Allowed, 405. |
HttpExchange.internalServerError (httpExchange) | Updates the response with the status code Internal Server Error, 500. |
Class HttpExchange
The HttpExchange class wraps the HTTP request and response.
- httpExchange:getContext ()
-
Returns the HTTP context.
Only available during the request handling
Returns:
-
HttpContext
the HTTP context.
- httpExchange:getRequest ()
-
Returns the HTTP request.
Returns:
-
HttpRequest
the HTTP request.
- httpExchange:getResponse ()
-
Returns the HTTP response.
Returns:
-
HttpResponse
the HTTP response.
- httpExchange:getRequestMethod ()
-
Returns the HTTP request method.
Returns:
-
string
the HTTP method.
- httpExchange:getRequestHeaders ()
-
Returns the HTTP request headers.
Returns:
-
HttpHeaders
the HTTP request.
- httpExchange:getRequestArguments ()
-
Returns the captured values of the request target path using the context path.
Returns:
-
string
the first captured value, nil if there is no captured value.
- httpExchange:onRequestBody ([buffer])
-
Returns a promise that resolves once the request body is available.
Parameters:
- buffer boolean true to indicate that the request body must be bufferred. (optional)
Returns:
-
jls.lang.Promise
a promise that resolves once the request body is available.
- httpExchange:onClose ()
-
Returns a promise that resolves once the exchange is closed.
Returns:
-
jls.lang.Promise
a promise that resolves once the exchange is closed.
- httpExchange:setResponseStatusCode (statusCode[, reasonPhrase[, body]])
-
Sets the status code for the response.
Parameters:
- HttpExchange.ok (httpExchange[, body[, contentType]])
-
Updates the response with the OK status code, 200.
Parameters:
- httpExchange HttpExchange ongoing HTTP exchange
- body string the response content. (optional)
- contentType string the response content type. (optional)
- HttpExchange.badRequest (httpExchange[, reasonPhrase])
-
Updates the response with the status code Bad Request, 400.
Parameters:
- httpExchange HttpExchange ongoing HTTP exchange
- reasonPhrase string the response reason phrase. (optional)
- HttpExchange.forbidden (httpExchange[, reasonPhrase])
-
Updates the response with the status code Forbidden, 403.
Parameters:
- httpExchange HttpExchange ongoing HTTP exchange
- reasonPhrase string the response reason phrase. (optional)
- HttpExchange.notFound (httpExchange)
-
Updates the response with the status code Not Found, 404.
Parameters:
- httpExchange HttpExchange ongoing HTTP exchange
- HttpExchange.methodNotAllowed (httpExchange)
-
Updates the response with the status code Method Not Allowed, 405.
Parameters:
- httpExchange HttpExchange ongoing HTTP exchange
- HttpExchange.internalServerError (httpExchange)
-
Updates the response with the status code Internal Server Error, 500.
Parameters:
- httpExchange HttpExchange ongoing HTTP exchange