Search in sources :

Example 1 with AjpClientRequestClientStreamSinkChannel

use of io.undertow.protocols.ajp.AjpClientRequestClientStreamSinkChannel in project undertow by undertow-io.

the class AjpClientConnection method initiateRequest.

private void initiateRequest(AjpClientExchange AjpClientExchange) {
    currentRequest = AjpClientExchange;
    ClientRequest request = AjpClientExchange.getRequest();
    String connectionString = request.getRequestHeaders().getFirst(CONNECTION);
    if (connectionString != null) {
        if (CLOSE.equalToString(connectionString)) {
            state |= CLOSE_REQ;
        }
    } else if (request.getProtocol() != Protocols.HTTP_1_1) {
        state |= CLOSE_REQ;
    }
    if (request.getRequestHeaders().contains(UPGRADE)) {
        state |= UPGRADE_REQUESTED;
    }
    long length = 0;
    String fixedLengthString = request.getRequestHeaders().getFirst(CONTENT_LENGTH);
    String transferEncodingString = request.getRequestHeaders().getLast(TRANSFER_ENCODING);
    if (fixedLengthString != null) {
        length = Long.parseLong(fixedLengthString);
    } else if (transferEncodingString != null) {
        length = -1;
    }
    AjpClientRequestClientStreamSinkChannel sinkChannel = connection.sendRequest(request.getMethod(), request.getPath(), request.getProtocol(), request.getRequestHeaders(), request, requestFinishListener);
    currentRequest.setRequestChannel(sinkChannel);
    AjpClientExchange.invokeReadReadyCallback(AjpClientExchange);
    if (length == 0) {
        // otherwise it is up to the user
        try {
            sinkChannel.shutdownWrites();
            if (!sinkChannel.flush()) {
                handleFailedFlush(sinkChannel);
            }
        } catch (Throwable t) {
            handleError((t instanceof IOException) ? (IOException) t : new IOException(t));
        }
    }
}
Also used : IOException(java.io.IOException) ClientRequest(io.undertow.client.ClientRequest) AjpClientRequestClientStreamSinkChannel(io.undertow.protocols.ajp.AjpClientRequestClientStreamSinkChannel)

Aggregations

ClientRequest (io.undertow.client.ClientRequest)1 AjpClientRequestClientStreamSinkChannel (io.undertow.protocols.ajp.AjpClientRequestClientStreamSinkChannel)1 IOException (java.io.IOException)1