These function are not required if the javascript environment has its own HTTP parser. Just make sure the request from the HTTP parser has the structure the WebSocket functions expect.
To parse an HTTP buffer, use parseHttp.
To construct HTTP responses, use makeHttpResponse, makeHttpHtmlResponse or makeHttpHeaderResponse
To parse an HTTP buffer, use parseHttp.
To construct HTTP responses, use makeHttpResponse, makeHttpHtmlResponse or makeHttpHeaderResponse
Members
(inner) httpStatusCodes :string
The HTTP reasons. Can be extended for HTTP codes that are not implemented
Type:
-
string
Methods
(inner) isSameOrigin(origin, req) → {boolean}
Makes sure HTTP request comes from same origin
Parameters:
Name | Type | Description |
---|---|---|
origin |
string
|
The current origin |
req |
HttpRequest
|
The HTTP request to ensure comes from same origin |
Returns:
- Type:
-
boolean
If the request is from same origin
(inner) makeHttpHeaderResponse(code, headers) → {string}
Makes a simple HTTP response with customizable headers. A body can be concatenated onto the response if the correct headers are set manually
Parameters:
Name | Type | Description |
---|---|---|
code |
number
|
The HTTP status code to use |
headers |
Object
|
The headers to insert into the HTTP response |
Returns:
- Type:
-
string
The HTTP response containing the headers
(inner) makeHttpHtmlResponse(body, codeopt) → {string}
Makes a simple HTTP response with HTML content
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
body |
string
|
The HTML content to make an HTTP response for | ||
code |
number
|
<optional> |
200 | The HTTP status code to use |
Returns:
- Type:
-
string
The HTTP response containing the body
(inner) makeHttpResponse(code, done) → {string}
Makes a simple HTTP response without a body and only required headers
Parameters:
Name | Type | Description |
---|---|---|
code |
number
|
The HTTP status code to use |
done |
boolan
|
Indicates if the HTTP response is complete or should be concatenatable |
Returns:
- Type:
-
string
The HTTP response
(inner) parseHttp(buffer) → {HttpRequest}
Parses an incomming HTTP request from a TCP socket
- Source:
- To Do:
-
- this assumes that the http request is contained within a single tcp packet
- add some error handling to make sure it is http protocol
Parameters:
Name | Type | Description |
---|---|---|
buffer |
ArrayBuffer
|
The HTTP buffer received from the client |