Refine search
private String getPrincipal(HttpServerExchange exchange) { for(HttpString header : identityHeaders) { String res = exchange.getRequestHeaders().getFirst(header); if(res != null) { return res; } } return null; }
@Override public Optional<String> header(final String name) { return Optional.ofNullable(exchange.getRequestHeaders().getFirst(name)); }
private String getHostName(final HttpServerExchange exchange) { String hostName = exchange.getRequestHeaders().getFirst(HOST); if (hostName != null) { if (hostName.startsWith("[") && hostName.contains("]")) { hostName = hostName.substring(0, hostName.indexOf(']') + 1); } else if (hostName.contains(":")) { hostName = hostName.substring(0, hostName.indexOf(":")); } return hostName; } return null; }
/** * Handles the if-none-match header. returns true if the request should proceed, false otherwise * * @param exchange the exchange * @param etags The etags * @return */ public static boolean handleIfNoneMatch(final HttpServerExchange exchange, final List<ETag> etags, boolean allowWeak) { return handleIfNoneMatch(exchange.getRequestHeaders().getFirst(Headers.IF_NONE_MATCH), etags, allowWeak); }
/** * Handles the if-match header. returns true if the request should proceed, false otherwise * * @param exchange the exchange * @param etags The etags * @return */ public static boolean handleIfMatch(final HttpServerExchange exchange, final List<ETag> etags, boolean allowWeak) { return handleIfMatch(exchange.getRequestHeaders().getFirst(Headers.IF_MATCH), etags, allowWeak); }
@Override public boolean isRequestTrailerFieldsSupported() { if(current == null) { return false; } String te = current.getRequestHeaders().getFirst(Headers.TRANSFER_ENCODING); if(te == null) { return false; } return te.equalsIgnoreCase(Headers.CHUNKED.toString()); }
/** * Handles the if-modified-since header. returns true if the request should proceed, false otherwise * * @param exchange the exchange * @param lastModified The last modified date * @return */ public static boolean handleIfModifiedSince(final HttpServerExchange exchange, final Date lastModified) { return handleIfModifiedSince(exchange.getRequestHeaders().getFirst(Headers.IF_MODIFIED_SINCE), lastModified); }
/** * Handles the if-unmodified-since header. returns true if the request should proceed, false otherwise * * @param exchange the exchange * @param lastModified The last modified date * @return */ public static boolean handleIfUnmodifiedSince(final HttpServerExchange exchange, final Date lastModified) { return handleIfUnmodifiedSince(exchange.getRequestHeaders().getFirst(Headers.IF_UNMODIFIED_SINCE), lastModified); }
/** * Support API to API calls with scope token. The token is the original token from consumer and * the client credentials token of caller API is added from cache. * * This method is used in API to API call * * @param request the http request * @param exchange the http server exchange * @throws ClientException client exception * @throws ApiException api exception */ public void propagateHeaders(ClientRequest request, final HttpServerExchange exchange) throws ClientException, ApiException { String tid = exchange.getRequestHeaders().getFirst(HttpStringConstants.TRACEABILITY_ID); String token = exchange.getRequestHeaders().getFirst(Headers.AUTHORIZATION); String cid = exchange.getRequestHeaders().getFirst(HttpStringConstants.CORRELATION_ID); populateHeader(request, token, cid, tid); }
@Override public String getRequestHeader(final String headerName) { return exchange.getRequestHeaders().getFirst(HttpString.tryFromString(headerName)); }
@Override public FormDataParser create(final HttpServerExchange exchange) { String mimeType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE); if (forceCreation || (mimeType != null && mimeType.startsWith(APPLICATION_X_WWW_FORM_URLENCODED))) { String charset = defaultEncoding; String contentType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE); if (contentType != null) { String cs = Headers.extractQuotedValueFromHeader(contentType, "charset"); if (cs != null) { charset = cs; } } UndertowLogger.REQUEST_LOGGER.tracef("Created form encoded parser for %s", exchange); return new FormEncodedDataParser(charset, exchange); } return null; }
@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 { final String upgrade = exchange.getRequestHeaders().getFirst(Headers.UPGRADE); final String settings = exchange.getRequestHeaders().getFirst("HTTP2-Settings"); if(settings != null && upgrade != null && upgradeStrings.contains(upgrade)) { if(HttpContinue.requiresContinueResponse(exchange) && false) { HttpContinue.sendContinueResponse(exchange, new IoCallback() { @Override public void onComplete(HttpServerExchange exchange, Sender sender) { try { handleUpgradeBody(exchange, upgrade, settings); } catch (Exception e) { throw new RuntimeException(e); } } @Override public void onException(HttpServerExchange exchange, Sender sender, IOException exception) { exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR); exchange.endExchange(); } }); } else { handleUpgradeBody(exchange, upgrade, settings); } return; } next.handleRequest(exchange); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { final String hostHeader = exchange.getRequestHeaders().getFirst(Headers.HOST); if (hostHeader != null) { String host; if (hostHeader.contains(":")) { //header can be in host:port format host = hostHeader.substring(0, hostHeader.lastIndexOf(":")); } else { host = hostHeader; } //most hosts will be lowercase, so we do the host HttpHandler handler = hosts.get(host); if (handler != null) { handler.handleRequest(exchange); return; } //do a cache insensitive match handler = hosts.get(host.toLowerCase(Locale.ENGLISH)); if (handler != null) { handler.handleRequest(exchange); return; } } defaultHandler.handleRequest(exchange); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { // check if the cid is in the request header String cId = exchange.getRequestHeaders().getFirst(HttpStringConstants.CORRELATION_ID); if(cId == null) { // if not, generate a UUID and put it into the request header cId = Util.getUUID(); exchange.getRequestHeaders().put(HttpStringConstants.CORRELATION_ID, cId); } // Add the cId into MDC so that all log statement will have cId as part of it. MDC.put(CID, cId); //logger.debug("Init cId:" + cId); Handler.next(exchange, next); }
String hostname = exchange.getRequestHeaders().getFirst(Headers.HOST); if (hostname != null) {
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { HeaderMap requestHeaders = exchange.getRequestHeaders(); final String sessionId = requestHeaders.getFirst(SSL_SESSION_ID); final String cipher = requestHeaders.getFirst(SSL_CIPHER); String clientCert = requestHeaders.getFirst(SSL_CLIENT_CERT); //the proxy client replaces \n with ' ' if (clientCert != null && clientCert.length() > 28) { StringBuilder sb = new StringBuilder(clientCert.length() + 1); sb.append(Certificates.BEGIN_CERT); sb.append('\n'); sb.append(clientCert.replace(' ', '\n').substring(28, clientCert.length() - 26));//core certificate data sb.append('\n'); sb.append(Certificates.END_CERT); clientCert = sb.toString(); } if (clientCert != null || sessionId != null || cipher != null) { try { SSLSessionInfo info = new BasicSSLSessionInfo(sessionId, cipher, clientCert); exchange.setRequestScheme(HTTPS); exchange.getConnection().setSslSessionInfo(info); exchange.addExchangeCompleteListener(CLEAR_SSL_LISTENER); } catch (java.security.cert.CertificateException | CertificateException e) { UndertowLogger.REQUEST_LOGGER.debugf(e, "Could not create certificate from header %s", clientCert); } } 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); } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { String tid = exchange.getRequestHeaders().getFirst(HttpStringConstants.TRACEABILITY_ID); if(tid != null) { exchange.getResponseHeaders().put(HttpStringConstants.TRACEABILITY_ID, tid); } Handler.next(exchange, next); }
@Override public ChallengeResult sendChallenge(HttpServerExchange exchange, SecurityContext securityContext) { if(silent) { //if this is silent we only send a challenge if the request contained auth headers //otherwise we assume another method will send the challenge String authHeader = exchange.getRequestHeaders().getFirst(AUTHORIZATION); if(authHeader == null) { return ChallengeResult.NOT_SENT; } } exchange.getResponseHeaders().add(WWW_AUTHENTICATE, challenge); UndertowLogger.SECURITY_LOGGER.debugf("Sending basic auth challenge %s for %s", challenge, exchange); return new ChallengeResult(true, UNAUTHORIZED); }