Module jls.net.http.HttpMessage
Represents an HTTP request or response.
Class HttpMessage
HttpMessage:new () | Creates a new Message. |
httpMessage:getVersion () | Returns the version of this HTTP message, default to HTTP/1.1 . |
httpMessage:setVersion (version) | Sets the first line of this HTTP message. |
httpMessage:getStatusCode () | Returns this HTTP response status code. |
httpMessage:getReasonPhrase () | Returns this HTTP response reason phrase. |
httpMessage:setStatusCode (status[, reason]) | Sets the status code for the response. |
httpMessage:getMethod () | Returns this HTTP request method, GET, POST. |
httpMessage:setMethod (value) | Sets this HTTP request method. |
httpMessage:getTarget () | Returns this HTTP request target. |
httpMessage:setTarget (value) | Sets this HTTP request target. |
httpMessage:getBodyStreamHandler () | Returns the stream handler associated to the body. |
httpMessage:setBodyStreamHandler (sh) | Sets the stream handler associated to the body. |
httpMessage:getBody () | Returns the body of this HTTP message. |
httpMessage:setBody (value) | Sets the body of this HTTP message. |
httpMessage:onWriteBodyStreamHandler ([callback]) | Sets a function that will be called when the body stream handler is available to receive data. |
httpMessage:consume () | Consumes the body. |
httpMessage:text () | Reads the message body as text. |
httpMessage:json () | Reads the message body as JSON. |
Class HttpMessage
The HttpMessage class represents the base class for HTTP request and HTTP response.
This class inherits from HttpHeaders.
- HttpMessage:new ()
- Creates a new Message.
- httpMessage:getVersion ()
-
Returns the version of this HTTP message, default to
HTTP/1.1
.Returns:
-
string
the version of this HTTP message.
- httpMessage:setVersion (version)
-
Sets the first line of this HTTP message.
Parameters:
- version string the first line.
- httpMessage:getStatusCode ()
-
Returns this HTTP response status code.
Returns:
- number the HTTP response status code.
- string the HTTP response reason phrase.
- httpMessage:getReasonPhrase ()
-
Returns this HTTP response reason phrase.
Returns:
-
string
the HTTP response reason phrase.
- httpMessage:setStatusCode (status[, reason])
-
Sets the status code for the response.
Parameters:
- status number the status code.
- reason string the reason phrase. (optional)
Returns:
-
HttpMessage
this message.
- httpMessage:getMethod ()
-
Returns this HTTP request method, GET, POST.
Returns:
-
string
the HTTP request method.
- httpMessage:setMethod (value)
-
Sets this HTTP request method.
Parameters:
- value string the method.
- httpMessage:getTarget ()
-
Returns this HTTP request target.
Returns:
-
string
the HTTP request target.
- httpMessage:setTarget (value)
-
Sets this HTTP request target.
Parameters:
- value string the target.
- httpMessage:getBodyStreamHandler ()
-
Returns the stream handler associated to the body.
The default value is the null stream handler.
Returns:
-
StreamHandler
the body stream handler.
- httpMessage:setBodyStreamHandler (sh)
-
Sets the stream handler associated to the body.
Parameters:
- sh StreamHandler the body stream handler.
- httpMessage:getBody ()
-
Returns the body of this HTTP message.
Returns:
-
string
the body of this HTTP message.
- httpMessage:setBody (value)
-
Sets the body of this HTTP message.
Parameters:
- value string the body.
- httpMessage:onWriteBodyStreamHandler ([callback])
-
Sets a function that will be called when the body stream handler is available to receive data.
The default callback will emit the string body value.
It is the caller's responsability to ensure that the content length or message headers are correctly set.
Parameters:
- callback function the function to call when the body stream handler is available. (optional)
Returns:
-
a promise that resolves once the body stream handler is available.
- httpMessage:consume ()
-
Consumes the body.
Returns:
-
a promise that resolves once the body has been received.
- httpMessage:text ()
-
Reads the message body as text.
Returns:
-
a promise that resolves to the body content as text.
- httpMessage:json ()
-
Reads the message body as JSON.
Returns:
-
a promise that resolves to the body content as JSON.