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;
}
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);
}
});
}
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);
}
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;
}
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);
}
Aggregations