HTTPServerPipelineHandler

A ChannelHandler that handles HTTP pipelining by buffering inbound data until a response has been sent.

HTTPServerPipelineHandler.swift:44
final class HTTPServerPipelineHandler

This handler ensures that HTTP server pipelines only process one request at a time. This is the safest way for pipelining-unaware code to operate, as it ensures that mutation of any shared server state is not parallelised, and that responses are always sent for each request in turn. In almost all cases this is the behaviour that a pipeline will want. This is achieved without doing too much buffering by preventing the Channel from reading from the socket until a complete response is processed, ensuring that a malicious client is not capable of overwhelming a server by shoving an enormous amount of data down the Channel while a server is processing a slow response.

See RFC 7320 Section 6.3.2 for more details on safely handling HTTP pipelining.

In addition to handling the request buffering, this ChannelHandler is aware of TCP half-close. While there are very few HTTP clients that are capable of TCP half-close, clients that are not HTTP specific (e.g. netcat) may trigger a TCP half-close. Having this ChannelHandler be aware of TCP half-close makes it easier to build HTTP servers that are resilient to this kind of behaviour.

The TCP half-close handling is done by buffering the half-close notification along with the HTTP request parts. The half-close notification will be delivered in order with the rest of the reads. If the half-close occurs either before a request is received or during a request body upload, it will be delivered immediately. If a half-close is received immediately after HTTPServerRequestPart.end, it will also be passed along immediately, allowing this signal to be seen by the HTTP server as early as possible.