Search in sources :

Example 1 with LineTooLargeException

use of org.httpkit.LineTooLargeException in project http-kit by http-kit.

the class HttpServer method decodeHttp.

private void decodeHttp(HttpAtta atta, SelectionKey key, SocketChannel ch) {
    try {
        boolean sentContinue = false;
        do {
            AsyncChannel channel = atta.channel;
            HttpRequest request = atta.decoder.decode(buffer);
            if (request != null) {
                if (status.get() != Status.RUNNING) {
                    request.isKeepAlive = false;
                }
                channel.reset(request);
                if (request.isWebSocket) {
                    key.attach(new WsAtta(channel, maxWs));
                } else {
                    atta.keepalive = request.isKeepAlive;
                }
                request.channel = channel;
                request.remoteAddr = (InetSocketAddress) ch.socket().getRemoteSocketAddress();
                handler.handle(request, new RespCallback(key, this));
                // pipelining not supported : need queue to ensure order
                atta.decoder.reset();
            } else if (!sentContinue && atta.decoder.requiresContinue()) {
                tryWrite(key, HttpEncode(100, new HeaderMap(), null, serverHeader));
                sentContinue = true;
            }
        } while (// consume all
        buffer.hasRemaining());
    } catch (ProtocolException e) {
        closeKey(key, -1);
    } catch (RequestTooLargeException e) {
        atta.keepalive = false;
        eventLogger.log(eventNames.serverStatus413);
        tryWrite(key, HttpEncode(413, new HeaderMap(), e.getMessage(), serverHeader));
    } catch (LineTooLargeException e) {
        // close after write
        atta.keepalive = false;
        eventLogger.log(eventNames.serverStatus414);
        tryWrite(key, HttpEncode(414, new HeaderMap(), e.getMessage(), serverHeader));
    }
}
Also used : ProtocolException(org.httpkit.ProtocolException) LineTooLargeException(org.httpkit.LineTooLargeException) HeaderMap(org.httpkit.HeaderMap) RequestTooLargeException(org.httpkit.RequestTooLargeException)

Aggregations

HeaderMap (org.httpkit.HeaderMap)1 LineTooLargeException (org.httpkit.LineTooLargeException)1 ProtocolException (org.httpkit.ProtocolException)1 RequestTooLargeException (org.httpkit.RequestTooLargeException)1