Search in sources :

Example 1 with EmptyStreamSourceConduit

use of io.undertow.conduits.EmptyStreamSourceConduit in project undertow by undertow-io.

the class HttpServerExchange method getRequestChannel.

/**
     * Get the inbound request.  If there is no request body, calling this method
     * may cause the next request to immediately be processed.  The {@link StreamSourceChannel#close()} or {@link StreamSourceChannel#shutdownReads()}
     * method must be called at some point after the request is processed to prevent resource leakage and to allow
     * the next request to proceed.  Any unread content will be discarded.
     *
     * @return the channel for the inbound request, or {@code null} if another party already acquired the channel
     */
public StreamSourceChannel getRequestChannel() {
    if (requestChannel != null) {
        if (anyAreSet(state, FLAG_REQUEST_RESET)) {
            state &= ~FLAG_REQUEST_RESET;
            return requestChannel;
        }
        return null;
    }
    if (anyAreSet(state, FLAG_REQUEST_TERMINATED)) {
        return requestChannel = new ReadDispatchChannel(new ConduitStreamSourceChannel(Configurable.EMPTY, new EmptyStreamSourceConduit(getIoThread())));
    }
    final ConduitWrapper<StreamSourceConduit>[] wrappers = this.requestWrappers;
    final ConduitStreamSourceChannel sourceChannel = connection.getSourceChannel();
    if (wrappers != null) {
        this.requestWrappers = null;
        final WrapperConduitFactory<StreamSourceConduit> factory = new WrapperConduitFactory<>(wrappers, requestWrapperCount, sourceChannel.getConduit(), this);
        sourceChannel.setConduit(factory.create());
    }
    return requestChannel = new ReadDispatchChannel(sourceChannel);
}
Also used : EmptyStreamSourceConduit(io.undertow.conduits.EmptyStreamSourceConduit) ConduitStreamSourceChannel(org.xnio.conduits.ConduitStreamSourceChannel) StreamSourceConduit(org.xnio.conduits.StreamSourceConduit) EmptyStreamSourceConduit(io.undertow.conduits.EmptyStreamSourceConduit)

Example 2 with EmptyStreamSourceConduit

use of io.undertow.conduits.EmptyStreamSourceConduit in project undertow by undertow-io.

the class AjpReadListener method createSourceConduit.

private StreamSourceConduit createSourceConduit(StreamSourceConduit underlyingConduit, AjpServerResponseConduit responseConduit, final HttpServerExchange exchange) {
    ReadDataStreamSourceConduit conduit = new ReadDataStreamSourceConduit(underlyingConduit, (AbstractServerConnection) exchange.getConnection());
    final HeaderMap requestHeaders = exchange.getRequestHeaders();
    HttpString transferEncoding = Headers.IDENTITY;
    Long length;
    final String teHeader = requestHeaders.getLast(Headers.TRANSFER_ENCODING);
    boolean hasTransferEncoding = teHeader != null;
    if (hasTransferEncoding) {
        transferEncoding = new HttpString(teHeader);
    }
    final String requestContentLength = requestHeaders.getFirst(Headers.CONTENT_LENGTH);
    if (hasTransferEncoding && !transferEncoding.equals(Headers.IDENTITY)) {
        //unknown length
        length = null;
    } else if (requestContentLength != null) {
        final long contentLength = Long.parseLong(requestContentLength);
        if (contentLength == 0L) {
            UndertowLogger.REQUEST_LOGGER.trace("No content, starting next request");
            // no content - immediately start the next request, returning an empty stream for this one
            Connectors.terminateRequest(httpServerExchange);
            return new EmptyStreamSourceConduit(conduit.getReadThread());
        } else {
            length = contentLength;
        }
    } else {
        UndertowLogger.REQUEST_LOGGER.trace("No content length or transfer coding, starting next request");
        // no content - immediately start the next request, returning an empty stream for this one
        Connectors.terminateRequest(exchange);
        return new EmptyStreamSourceConduit(conduit.getReadThread());
    }
    return new AjpServerRequestConduit(conduit, exchange, responseConduit, length, new ConduitListener<AjpServerRequestConduit>() {

        @Override
        public void handleEvent(AjpServerRequestConduit channel) {
            Connectors.terminateRequest(exchange);
        }
    });
}
Also used : EmptyStreamSourceConduit(io.undertow.conduits.EmptyStreamSourceConduit) HeaderMap(io.undertow.util.HeaderMap) ReadDataStreamSourceConduit(io.undertow.conduits.ReadDataStreamSourceConduit) HttpString(io.undertow.util.HttpString) HttpString(io.undertow.util.HttpString)

Aggregations

EmptyStreamSourceConduit (io.undertow.conduits.EmptyStreamSourceConduit)2 ReadDataStreamSourceConduit (io.undertow.conduits.ReadDataStreamSourceConduit)1 HeaderMap (io.undertow.util.HeaderMap)1 HttpString (io.undertow.util.HttpString)1 ConduitStreamSourceChannel (org.xnio.conduits.ConduitStreamSourceChannel)1 StreamSourceConduit (org.xnio.conduits.StreamSourceConduit)1