@Override @Nullable public List<String> remove(Object key) { if (key instanceof String) { this.headers.remove((String) key); } return null; }
@Override @Nullable public List<String> remove(Object key) { if (key instanceof String) { this.headers.remove((String) key); } return null; }
/** * Sets the response content length * * @param length The content length */ public HttpServerExchange setResponseContentLength(long length) { if (length == -1) { responseHeaders.remove(Headers.CONTENT_LENGTH); } else { responseHeaders.put(Headers.CONTENT_LENGTH, Long.toString(length)); } return this; }
public HeaderMap putAll(HttpString headerName, Collection<String> headerValues) { if (headerName == null) { throw new IllegalArgumentException("headerName is null"); } if (headerValues == null || headerValues.isEmpty()) { remove(headerName); return this; } final HeaderValues entry = getOrCreateEntry(headerName); entry.clear(); entry.addAll(headerValues); return this; }
public HeaderMap put(HttpString headerName, String headerValue) { if (headerName == null) { throw new IllegalArgumentException("headerName is null"); } if (headerValue == null) { remove(headerName); return this; } final HeaderValues headerValues = getOrCreateEntry(headerName); headerValues.clear(); headerValues.add(headerValue); return this; }
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), Protocols.HTTP_2_0, headers); } }
@Override public void header(final String name, final String value) { if ("Content-Length".equalsIgnoreCase(name)) { exchange.getResponseHeaders().remove(Headers.TRANSFER_ENCODING); } exchange.getResponseHeaders().put(HttpString.tryFromString(name), value); }
private static StreamSinkConduit handleFixedLength(HttpServerExchange exchange, boolean headRequest, StreamSinkConduit channel, HeaderMap responseHeaders, String contentLengthHeader, HttpServerConnection connection) { try { final long contentLength = parsePositiveLong(contentLengthHeader); if (headRequest) { return channel; } // fixed-length response ServerFixedLengthStreamSinkConduit fixed = connection.getFixedLengthStreamSinkConduit(); fixed.reset(contentLength, exchange); return fixed; } catch (NumberFormatException e) { //we just fix it for them responseHeaders.remove(Headers.CONTENT_LENGTH); } return null; }
private StreamSinkConduit createNextChannel() { if (deflater.finished() && allAreSet(state, WRITTEN_TRAILER)) { //the deflater was fully flushed before we created the channel. This means that what is in the buffer is //all there is int remaining = currentBuffer.getBuffer().remaining(); if (additionalBuffer != null) { remaining += additionalBuffer.remaining(); } if(!exchange.getResponseHeaders().contains(Headers.TRANSFER_ENCODING)) { exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, Integer.toString(remaining)); } } else { exchange.getResponseHeaders().remove(Headers.CONTENT_LENGTH); } return conduitFactory.create(); }
List<String> requestHeaderRemove = (List<String>)requestHeaderMap.get(REMOVE); if(requestHeaderRemove != null) { requestHeaderRemove.forEach(s -> exchange.getRequestHeaders().remove(s)); List<String> responseHeaderRemove = (List<String>)responseHeaderMap.get(REMOVE); if(responseHeaderRemove != null) { responseHeaderRemove.forEach(s -> exchange.getResponseHeaders().remove(s));
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { ConduitWrapper<StreamSourceConduit> encodings = requestEncodings.get(exchange.getRequestHeaders().getFirst(Headers.CONTENT_ENCODING)); if (encodings != null && exchange.isRequestChannelAvailable()) { exchange.addRequestWrapper(encodings); // Nested handlers or even servlet filters may implement logic to decode encoded request data. // Since the data is no longer encoded, we remove the encoding header. exchange.getRequestHeaders().remove(Headers.CONTENT_ENCODING); } next.handleRequest(exchange); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { ConduitWrapper<StreamSourceConduit> encodings = requestEncodings.get(exchange.getRequestHeaders().getFirst(Headers.CONTENT_ENCODING)); if (encodings != null && exchange.isRequestChannelAvailable()) { exchange.addRequestWrapper(encodings); // Nested handlers or even servlet filters may implement logic to decode encoded request data. // Since the data is no longer encoded, we remove the encoding header. exchange.getRequestHeaders().remove(Headers.CONTENT_ENCODING); } Handler.next(exchange, next); } }
if (!headers.contains(Headers.CONTENT_LENGTH)) { headers.put(Headers.CONTENT_LENGTH, count); headers.remove(Headers.TRANSFER_ENCODING);
@Override public void terminateWrites() throws IOException { if(anyAreSet(state, FLAG_WRITES_SHUTDOWN)) { return; } if (this.chunkleft != 0) { UndertowLogger.REQUEST_IO_LOGGER.debugf("Channel closed mid-chunk"); next.truncateWrites(); } if (!anyAreSet(state, FLAG_FIRST_DATA_WRITTEN)) { //if no data was actually sent we just remove the transfer encoding header, and set content length 0 //TODO: is this the best way to do it? //todo: should we make this behaviour configurable? responseHeaders.put(Headers.CONTENT_LENGTH, "0"); //according to the spec we don't actually need this, but better to be safe responseHeaders.remove(Headers.TRANSFER_ENCODING); state |= FLAG_NEXT_SHUTDOWN | FLAG_WRITES_SHUTDOWN; if(anyAreSet(state, CONF_FLAG_PASS_CLOSE)) { next.terminateWrites(); } } else { createLastChunk(false); state |= FLAG_WRITES_SHUTDOWN; } }
exchange.getRequestHeaders().remove(Headers.UPGRADE); outboundRequestHeaders.put(Headers.CONNECTION, "keep-alive"); String headerValue = entry.getValue().readAttribute(exchange); if (headerValue == null || headerValue.isEmpty()) { outboundRequestHeaders.remove(entry.getKey()); } else { outboundRequestHeaders.put(entry.getKey(), headerValue.replace('\n', ' '));
} else if(!Connectors.isEntityBodyAllowed(exchange)) { exchange.getResponseHeaders().remove(Headers.CONTENT_LENGTH); exchange.getResponseHeaders().remove(Headers.TRANSFER_ENCODING); channel = new HeadStreamSinkConduit(channel, terminateResponseListener(exchange)); return channel; responseHeaders.remove(Headers.CONTENT_LENGTH); //if there is a transfer-encoding header we remove content length if present
@Override public PushBuilder removeHeader(String name) { headers.remove(name); return this; }