@Override public OptionMap getOptions() { return exchange.getConnection().getUndertowOptions(); } }
public static String getQueryParamEncoding(HttpServerExchange exchange) { String encoding = null; OptionMap undertowOptions = exchange.getConnection().getUndertowOptions(); if(undertowOptions.get(UndertowOptions.DECODE_URL, true)) { encoding = undertowOptions.get(UndertowOptions.URL_CHARSET, StandardCharsets.UTF_8.name()); } return encoding; } }
/** * Sets the request path and query parameters, decoding to the requested charset. * * @param exchange The exchange * @param encodedPath The encoded path * @param charset The charset */ @Deprecated public static void setExchangeRequestPath(final HttpServerExchange exchange, final String encodedPath, final String charset, boolean decode, final boolean allowEncodedSlash, StringBuilder decodeBuffer) { try { setExchangeRequestPath(exchange, encodedPath, charset, decode, allowEncodedSlash, decodeBuffer, exchange.getConnection().getUndertowOptions().get(UndertowOptions.MAX_PARAMETERS, UndertowOptions.DEFAULT_MAX_PARAMETERS)); } catch (ParameterLimitException e) { throw new RuntimeException(e); } } /**
private FormEncodedDataParser(final String charset, final HttpServerExchange exchange) { this.exchange = exchange; this.charset = charset; this.data = new FormData(exchange.getConnection().getUndertowOptions().get(UndertowOptions.MAX_PARAMETERS, 1000)); }
/** * @return A mutable map of request cookies */ public Map<String, Cookie> getRequestCookies() { if (requestCookies == null) { requestCookies = Cookies.parseRequestCookies( getConnection().getUndertowOptions().get(UndertowOptions.MAX_COOKIES, 200), getConnection().getUndertowOptions().get(UndertowOptions.ALLOW_EQUALS_IN_COOKIE_VALUE, false), requestHeaders.get(Headers.COOKIE)); } return requestCookies; }
/** * Flattens the exchange cookie map into the response header map. This should be called by a * connector just before the response is started. * * @param exchange The server exchange */ public static void flattenCookies(final HttpServerExchange exchange) { Map<String, Cookie> cookies = exchange.getResponseCookiesInternal(); boolean enableRfc6265Validation = exchange.getConnection().getUndertowOptions().get(UndertowOptions.ENABLE_RFC6265_COOKIE_VALIDATION, UndertowOptions.DEFAULT_ENABLE_RFC6265_COOKIE_VALIDATION); if (cookies != null) { for (Map.Entry<String, Cookie> entry : cookies.entrySet()) { exchange.getResponseHeaders().add(Headers.SET_COOKIE, getCookieString(entry.getValue(), enableRfc6265Validation)); } } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { boolean decodeDone = exchange.getConnection().getUndertowOptions().get(UndertowOptions.DECODE_URL, true); if (!decodeDone) { final StringBuilder sb = new StringBuilder(); final boolean decodeSlash = exchange.getConnection().getUndertowOptions().get(UndertowOptions.ALLOW_ENCODED_SLASH, false); exchange.setRequestPath(URLUtils.decode(exchange.getRequestPath(), charset, decodeSlash, false, sb)); exchange.setRelativePath(URLUtils.decode(exchange.getRelativePath(), charset, decodeSlash, false, sb));
int maxData = exchange.getConnection().getUndertowOptions().get(UndertowOptions.MAX_AJP_PACKET_SIZE, DEFAULT_MAX_DATA_SIZE) - 8; if (src.remaining() > maxData) { src.limit(src.position() + maxData);
public static void addDateHeaderIfRequired(HttpServerExchange exchange) { HeaderMap responseHeaders = exchange.getResponseHeaders(); if (exchange.getConnection().getUndertowOptions().get(UndertowOptions.ALWAYS_SET_DATE, true) && !responseHeaders.contains(Headers.DATE)) { String dateString = getCurrentDateTime(exchange); responseHeaders.put(Headers.DATE, dateString); } }
/** * Sets a response cookie * * @param cookie The cookie */ public HttpServerExchange setResponseCookie(final Cookie cookie) { if(getConnection().getUndertowOptions().get(UndertowOptions.ENABLE_RFC6265_COOKIE_VALIDATION, UndertowOptions.DEFAULT_ENABLE_RFC6265_COOKIE_VALIDATION)) { if (cookie.getValue() != null && !cookie.getValue().isEmpty()) { Rfc6265CookieSupport.validateCookieValue(cookie.getValue()); } if (cookie.getPath() != null && !cookie.getPath().isEmpty()) { Rfc6265CookieSupport.validatePath(cookie.getPath()); } if (cookie.getDomain() != null && !cookie.getDomain().isEmpty()) { Rfc6265CookieSupport.validateDomain(cookie.getDomain()); } } if (responseCookies == null) { responseCookies = new TreeMap<>(); //hashmap is slow to allocate in JDK7 } responseCookies.put(cookie.getName(), cookie); return this; }
private MultiPartUploadHandler(final HttpServerExchange exchange, final String boundary, final long maxIndividualFileSize, final long fileSizeThreshold, final String defaultEncoding) { this.exchange = exchange; this.maxIndividualFileSize = maxIndividualFileSize; this.defaultEncoding = defaultEncoding; this.fileSizeThreshold = fileSizeThreshold; this.data = new FormData(exchange.getConnection().getUndertowOptions().get(UndertowOptions.MAX_PARAMETERS, 1000)); String charset = defaultEncoding; String contentType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE); if (contentType != null) { String value = Headers.extractQuotedValueFromHeader(contentType, "charset"); if (value != null) { charset = value; } } this.parser = MultipartParser.beginParse(exchange.getConnection().getByteBufferPool(), this, boundary.getBytes(StandardCharsets.US_ASCII), charset); }
@Override public FormDataParser create(final HttpServerExchange exchange) { String mimeType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE); if (mimeType != null && mimeType.startsWith(MULTIPART_FORM_DATA)) { String boundary = Headers.extractQuotedValueFromHeader(mimeType, "boundary"); if (boundary == null) { UndertowLogger.REQUEST_LOGGER.debugf("Could not find boundary in multipart request with ContentType: %s, multipart data will not be available", mimeType); return null; } final MultiPartUploadHandler parser = new MultiPartUploadHandler(exchange, boundary, maxIndividualFileSize, fileSizeThreshold, defaultEncoding); exchange.addExchangeCompleteListener(new ExchangeCompletionListener() { @Override public void exchangeEvent(final HttpServerExchange exchange, final NextListener nextListener) { IoUtils.safeClose(parser); nextListener.proceed(); } }); Long sizeLimit = exchange.getConnection().getUndertowOptions().get(UndertowOptions.MULTIPART_MAX_ENTITY_SIZE); if(sizeLimit != null) { exchange.setMaxEntitySize(sizeLimit); } UndertowLogger.REQUEST_LOGGER.tracef("Created multipart parser for %s", exchange); return parser; } return null; }
public void renegotiateBufferRequest(HttpServerExchange exchange, SslClientAuthMode newAuthMode) throws IOException { int maxSize = exchange.getConnection().getUndertowOptions().get(UndertowOptions.MAX_BUFFERED_REQUEST_SIZE, UndertowOptions.DEFAULT_MAX_BUFFERED_REQUEST_SIZE); if (maxSize <= 0) { throw new SSLPeerUnverifiedException("");
@Override public void handleUpgrade(StreamConnection streamConnection, HttpServerExchange exchange) { OptionMap undertowOptions = exchange.getConnection().getUndertowOptions(); Http2Channel channel = new Http2Channel(streamConnection, upgrade, exchange.getConnection().getByteBufferPool(), null, false, true, true, settingsFrame, undertowOptions); Http2ReceiveListener receiveListener = new Http2ReceiveListener(new HttpHandler() { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { //if this header is present we don't actually process the rest of the handler chain //as the request was only to create the initial request if(exchange.getRequestHeaders().contains("X-HTTP2-connect-only")) { exchange.endExchange(); return; } exchange.setProtocol(Protocols.HTTP_2_0); next.handleRequest(exchange); } }, undertowOptions, exchange.getConnection().getBufferSize(), null); channel.getReceiveSetter().set(receiveListener); receiveListener.handleInitialRequest(exchange, channel, data); channel.resumeReceives(); } });
handleHttp2Upgrade(exchange, upgrade, settings, null); } else { final int maxBufferedSize = exchange.getConnection().getUndertowOptions().get(UndertowOptions.MAX_BUFFERED_REQUEST_SIZE, UndertowOptions.DEFAULT_MAX_BUFFERED_REQUEST_SIZE); if(exchange.getRequestContentLength() > maxBufferedSize) {
exchange.setPersistent(false); } else if (exchange.getConnection().getUndertowOptions().get(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, true)) { responseHeaders.put(Headers.CONNECTION, Headers.KEEP_ALIVE.toString());
@Override public OptionMap getOptions() { return exchange.getConnection().getUndertowOptions(); } }
public static String getQueryParamEncoding(HttpServerExchange exchange) { String encoding = null; OptionMap undertowOptions = exchange.getConnection().getUndertowOptions(); if(undertowOptions.get(UndertowOptions.DECODE_URL, true)) { encoding = undertowOptions.get(UndertowOptions.URL_CHARSET, StandardCharsets.UTF_8.name()); } return encoding; } }
private FormEncodedDataParser(final String charset, final HttpServerExchange exchange) { this.exchange = exchange; this.charset = charset; this.data = new FormData(exchange.getConnection().getUndertowOptions().get(UndertowOptions.MAX_PARAMETERS, 1000)); }
public static void addDateHeaderIfRequired(HttpServerExchange exchange) { HeaderMap responseHeaders = exchange.getResponseHeaders(); if (exchange.getConnection().getUndertowOptions().get(UndertowOptions.ALWAYS_SET_DATE, true) && !responseHeaders.contains(Headers.DATE)) { String dateString = getCurrentDateTime(exchange); responseHeaders.put(Headers.DATE, dateString); } }