Search in sources :

Example 11 with HeaderMap

use of io.undertow.util.HeaderMap in project undertow by undertow-io.

the class Http2ServerConnection method getSinkConduit.

@Override
protected StreamSinkConduit getSinkConduit(HttpServerExchange exchange, StreamSinkConduit conduit) {
    HeaderMap headers = responseChannel.getHeaders();
    DateUtils.addDateHeaderIfRequired(exchange);
    headers.add(STATUS, exchange.getStatusCode());
    Connectors.flattenCookies(exchange);
    return originalSinkConduit;
}
Also used : HeaderMap(io.undertow.util.HeaderMap)

Example 12 with HeaderMap

use of io.undertow.util.HeaderMap 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)

Example 13 with HeaderMap

use of io.undertow.util.HeaderMap in project indy by Commonjava.

the class HeaderDebugger method handleRequest.

@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("{} {}", exchange.getRequestMethod(), exchange.getRequestPath());
        logger.trace("FROM: {}", exchange.getSourceAddress());
        final HeaderMap headerMap = exchange.getRequestHeaders();
        final Collection<HttpString> names = headerMap.getHeaderNames();
        logger.trace("HEADERS: ");
        for (final HttpString name : names) {
            final HeaderValues values = headerMap.get(name);
            for (final String value : values) {
                logger.trace("{}: {}", name, value);
            }
        }
        logger.trace("COOKIES: ");
        final Map<String, Cookie> cookies = exchange.getRequestCookies();
        for (final String key : cookies.keySet()) {
            final Cookie cookie = cookies.get(key);
            if (cookie == null) {
                continue;
            }
            logger.trace("Cookie({}):\n  Domain: {}\n  Name: {}\n  Path: {}\n  Value: {}\n  Expires: {}\n  Max-Age: {}\n  Comment: {}\n  Version: {}\n\n", key, cookie.getDomain(), cookie.getName(), cookie.getPath(), cookie.getValue(), cookie.getExpires(), cookie.getMaxAge(), cookie.getComment(), cookie.getVersion());
        }
    }
    handler.handleRequest(exchange);
}
Also used : Cookie(io.undertow.server.handlers.Cookie) HeaderMap(io.undertow.util.HeaderMap) HeaderValues(io.undertow.util.HeaderValues) HttpString(io.undertow.util.HttpString) HttpString(io.undertow.util.HttpString)

Example 14 with HeaderMap

use of io.undertow.util.HeaderMap in project camel by apache.

the class DefaultUndertowHttpBinding method toHttpRequest.

@Override
public Object toHttpRequest(ClientRequest clientRequest, Message message) {
    Object body = message.getBody();
    final HeaderMap requestHeaders = clientRequest.getRequestHeaders();
    // set the content type in the response.
    String contentType = MessageHelper.getContentType(message);
    if (contentType != null) {
        // set content-type
        requestHeaders.put(Headers.CONTENT_TYPE, contentType);
        LOG.trace("Content-Type: {}", contentType);
    }
    TypeConverter tc = message.getExchange().getContext().getTypeConverter();
    //copy headers from Message to Request
    for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        // use an iterator as there can be multiple values. (must not use a delimiter)
        final Iterator<?> it = ObjectHelper.createIterator(value, null);
        while (it.hasNext()) {
            String headerValue = tc.convertTo(String.class, it.next());
            if (headerValue != null && headerFilterStrategy != null && !headerFilterStrategy.applyFilterToCamelHeaders(key, headerValue, message.getExchange())) {
                LOG.trace("HTTP-Header: {}={}", key, headerValue);
                requestHeaders.add(new HttpString(key), headerValue);
            }
        }
    }
    return body;
}
Also used : TypeConverter(org.apache.camel.TypeConverter) HeaderMap(io.undertow.util.HeaderMap) HttpString(io.undertow.util.HttpString) HashMap(java.util.HashMap) HeaderMap(io.undertow.util.HeaderMap) Map(java.util.Map) HttpString(io.undertow.util.HttpString)

Example 15 with HeaderMap

use of io.undertow.util.HeaderMap in project undertow by undertow-io.

the class Http2ClientExchange method createResponse.

ClientResponse createResponse(Http2StreamSourceChannel result) {
    HeaderMap headers = result.getHeaders();
    final String status = result.getHeaders().getFirst(Http2Channel.STATUS);
    int statusCode = Integer.parseInt(status);
    headers.remove(Http2Channel.STATUS);
    return new ClientResponse(statusCode, status.substring(3), clientRequest.getProtocol(), headers);
}
Also used : ClientResponse(io.undertow.client.ClientResponse) HeaderMap(io.undertow.util.HeaderMap)

Aggregations

HeaderMap (io.undertow.util.HeaderMap)30 HttpString (io.undertow.util.HttpString)17 HeaderValues (io.undertow.util.HeaderValues)9 ByteBuffer (java.nio.ByteBuffer)7 PooledByteBuffer (io.undertow.connector.PooledByteBuffer)6 HttpServerExchange (io.undertow.server.HttpServerExchange)6 IOException (java.io.IOException)6 Http2HeadersStreamSinkChannel (io.undertow.protocols.http2.Http2HeadersStreamSinkChannel)3 HttpHandler (io.undertow.server.HttpHandler)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 BeforeClass (org.junit.BeforeClass)3 ClientRequest (io.undertow.client.ClientRequest)2 DigestAlgorithm (io.undertow.security.idm.DigestAlgorithm)2 ImmediatePooledByteBuffer (io.undertow.util.ImmediatePooledByteBuffer)2 ParameterLimitException (io.undertow.util.ParameterLimitException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2