Java Code Examples for io.undertow.server.Connectors#terminateRequest()

The following examples show how to use io.undertow.server.Connectors#terminateRequest() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChunkedStreamSourceConduit.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void updateRemainingAllowed(final int written) throws IOException {
    if (remainingAllowed == Long.MIN_VALUE) {
        if (exchange == null) {
            return;
        } else {
            long maxEntitySize = exchange.getMaxEntitySize();
            if (maxEntitySize <= 0) {
                return;
            }
            remainingAllowed = maxEntitySize;
        }
    }
    remainingAllowed -= written;
    if (remainingAllowed < 0) {
        //max entity size is exceeded
        Connectors.terminateRequest(exchange);
        closed = true;
        exchange.setPersistent(false);
        finishListener.handleEvent(this);
        throw UndertowMessages.MESSAGES.requestEntityWasTooLarge(exchange.getMaxEntitySize());
    }
}
 
Example 2
Source File: FixedLengthStreamSourceConduit.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void checkMaxSize(long state) throws IOException {
    if (anyAreClear(state, FLAG_LENGTH_CHECKED)) {
        HttpServerExchange exchange = this.exchange;
        if (exchange != null) {
            if (exchange.getMaxEntitySize() > 0 && exchange.getMaxEntitySize() < (state & MASK_COUNT)) {
                //max entity size is exceeded
                //we need to forcibly close the read side
                Connectors.terminateRequest(exchange);
                exchange.setPersistent(false);
                finishListener.handleEvent(this);
                this.state |= FLAG_FINISHED | FLAG_CLOSED;
                throw UndertowMessages.MESSAGES.requestEntityWasTooLarge(exchange.getMaxEntitySize());
            }
        }
        this.state |= FLAG_LENGTH_CHECKED;
    }
}
 
Example 3
Source File: HttpTransferEncoding.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static ConduitListener<FixedLengthStreamSourceConduit> fixedLengthDrainListener(final HttpServerExchange exchange) {
    return new ConduitListener<FixedLengthStreamSourceConduit>() {
        public void handleEvent(final FixedLengthStreamSourceConduit fixedLengthConduit) {
            long remaining = fixedLengthConduit.getRemaining();
            if (remaining > 0L) {
                UndertowLogger.REQUEST_LOGGER.requestWasNotFullyConsumed();
                exchange.setPersistent(false);
            }
            Connectors.terminateRequest(exchange);
        }
    };
}
 
Example 4
Source File: HttpTransferEncoding.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static ConduitListener<ChunkedStreamSourceConduit> chunkedDrainListener(final HttpServerExchange exchange) {
    return new ConduitListener<ChunkedStreamSourceConduit>() {
        public void handleEvent(final ChunkedStreamSourceConduit chunkedStreamSourceConduit) {
            if (!chunkedStreamSourceConduit.isFinished()) {
                UndertowLogger.REQUEST_LOGGER.requestWasNotFullyConsumed();
                exchange.setPersistent(false);
            }
            Connectors.terminateRequest(exchange);
        }
    };
}
 
Example 5
Source File: HttpTransferEncoding.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static void setupRequest(final HttpServerExchange exchange) {
    final HeaderMap requestHeaders = exchange.getRequestHeaders();
    final String connectionHeader = requestHeaders.getFirst(Headers.CONNECTION);
    final String transferEncodingHeader = requestHeaders.getLast(Headers.TRANSFER_ENCODING);
    final String contentLengthHeader = requestHeaders.getFirst(Headers.CONTENT_LENGTH);

    final HttpServerConnection connection = (HttpServerConnection) exchange.getConnection();
    //if we are already using the pipelineing buffer add it to the exchange
    PipeliningBufferingStreamSinkConduit pipeliningBuffer = connection.getPipelineBuffer();
    if (pipeliningBuffer != null) {
        pipeliningBuffer.setupPipelineBuffer(exchange);
    }
    ConduitStreamSourceChannel sourceChannel = connection.getChannel().getSourceChannel();
    sourceChannel.setConduit(connection.getReadDataStreamSourceConduit());

    boolean persistentConnection = persistentConnection(exchange, connectionHeader);

    if (transferEncodingHeader == null && contentLengthHeader == null) {
        if (persistentConnection
                && connection.getExtraBytes() != null
                && pipeliningBuffer == null
                && connection.getUndertowOptions().get(UndertowOptions.BUFFER_PIPELINED_DATA, false)) {
            pipeliningBuffer = new PipeliningBufferingStreamSinkConduit(connection.getOriginalSinkConduit(), connection.getByteBufferPool());
            connection.setPipelineBuffer(pipeliningBuffer);
            pipeliningBuffer.setupPipelineBuffer(exchange);
        }
        // no content - immediately start the next request, returning an empty stream for this one
        Connectors.terminateRequest(exchange);
    } else {
        persistentConnection = handleRequestEncoding(exchange, transferEncodingHeader, contentLengthHeader, connection, pipeliningBuffer, persistentConnection);
    }

    exchange.setPersistent(persistentConnection);

    if (!exchange.isRequestComplete() || connection.getExtraBytes() != null) {
        //if there is more data we suspend reads
        sourceChannel.setReadListener(null);
        sourceChannel.suspendReads();
    }

}