Configuration.encodeHTTPRequest()
Description
Appends an encodeHTTPRequest filter to the current pipeline layout.
An encodeHTTPRequest filter encodes HTTP/1 request messages into a raw byte stream.
- INPUT - HTTP/1 request Messages to encode.
- OUTPUT - Encoded Data stream from the input HTTP/1 request messages.
The encoder expects an input Message to have:
- head
- protocol - Can be "HTTP/1.0" or "HTTP/1.1" (Defaults to "HTTP/1.1")
- method - HTTP method such as "GET" and "POST" (Defaults to "GET")
- path - Requested URI (Defaults to "/")
- headers - Header fields
- body - Message body
If any fields are missing in Message.head, their default values will be taken.
This filter only supports HTTP/1.x. For compatibility with HTTP/2, check out muxHTTP().
Chunked transfer
When encoding a request, the Content-Length header needs to come before the body, so encodeHTTPRequest has to buffer the entire body until it sees a MessageEnd event, only by then can the filter output a value for Content-Length header, followed by the previously buffered body.
The buffering is limited to 4KB by default. When the buffered data is over 4KB, the encoder will opt for chunked encoding, where a Content-Length header is no longer needed. You can change this limit by the option bufferSize in the options parameter.
Syntax
pipy().pipeline().encodeHTTPRequest()pipy().pipeline().encodeHTTPRequest({bufferSize,})
Parameters
encodeHTTPRequest()
The same Configuration object.