@Override public String getMethodValue() { return this.exchange.getRequestMethod().toString(); }
@Override public boolean resolve(HttpServerExchange value) { return METHODS.contains(value.getRequestMethod()); }
@Override public String getMethodValue() { return this.exchange.getRequestMethod().toString(); }
@Override public boolean resolve(final HttpServerExchange value) { for(int i =0; i < methods.length; ++i) { if(value.getRequestMethod().equals(methods[i])) { return true; } } return false; }
@Override public String readAttribute(final HttpServerExchange exchange) { return exchange.getRequestMethod().toString(); }
@Override public String readAttribute(final HttpServerExchange exchange) { StringBuilder sb = new StringBuilder() .append(exchange.getRequestMethod().toString()) .append(' ') .append(exchange.getRequestURI()); if (!exchange.getQueryString().isEmpty()) { sb.append('?'); sb.append(exchange.getQueryString()); } sb.append(' ') .append(exchange.getProtocol().toString()).toString(); return sb.toString(); }
/** * * @return The number of bytes sent in the entity body */ public long getResponseBytesSent() { if(Connectors.isEntityBodyAllowed(this) && !getRequestMethod().equals(Methods.HEAD)) { return responseBytesSent; } else { return 0; //body is not allowed, even if we attempt to write it will be ignored } }
@Override public String toString() { return "HttpServerExchange{ " + getRequestMethod().toString() + " " + getRequestURI() + " request " + requestHeaders + " response " + responseHeaders + '}'; } }
/** * Updates the number of response bytes sent. Used when compression is in use * @param bytes The number of bytes to increase the response size by. May be negative */ void updateBytesSent(long bytes) { if(Connectors.isEntityBodyAllowed(this) && !getRequestMethod().equals(Methods.HEAD)) { responseBytesSent += bytes; } }
@Override public AuthenticationMechanismOutcome authenticate(final HttpServerExchange exchange, final SecurityContext securityContext) { if (exchange.getRequestPath().endsWith(postLocation) && exchange.getRequestMethod().equals(Methods.POST)) { return runFormAuth(exchange, securityContext); } else { return AuthenticationMechanismOutcome.NOT_ATTEMPTED; } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if (disallowedMethods.contains(exchange.getRequestMethod())) { exchange.setStatusCode(StatusCodes.METHOD_NOT_ALLOWED); exchange.endExchange(); } else { next.handleRequest(exchange); } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if (allowedMethods.contains(exchange.getRequestMethod())) { next.handleRequest(exchange); } else { exchange.setStatusCode(StatusCodes.METHOD_NOT_ALLOWED); exchange.endExchange(); } }
/** * * @param connectListener * @return */ public HttpServerExchange acceptConnectRequest(HttpUpgradeListener connectListener) { if(!getRequestMethod().equals(Methods.CONNECT)) { throw UndertowMessages.MESSAGES.notAConnectRequest(); } connection.setConnectListener(connectListener); return this; }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if(exchange.getRequestMethod().equals(Methods.OPTIONS) && exchange.getRelativePath().equals("*")) { //handle the OPTIONS requests //basically just return an empty response exchange.endExchange(); return; } next.handleRequest(exchange); } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if (exchange.getRequestMethod().equals(Methods.GET) && exchange.getRelativePath().matches(ACME_CHALLENGE_REGEX)) { super.handleRequest(exchange); } else { next.handleRequest(exchange); } } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { InetSocketAddress peer = exchange.getSourceAddress(); String endpoint = exchange.getRelativePath() + "@" + exchange.getRequestMethod().toString().toLowerCase(); if (!isAllowed(peer.getAddress(), endpoint)) { setExchangeStatus(exchange, INVALID_IP_FOR_PATH, peer.toString(), endpoint); return; } Handler.next(exchange, next); }
private boolean isUpgradeOrConnect(HttpServerExchange exchange) { return exchange.isUpgrade() || (exchange.getRequestMethod().equals(Methods.CONNECT) && ((HttpServerConnection)exchange.getConnection()).isConnectHandled() ); }
private boolean handleHttp2PriorKnowledge(PooledByteBuffer pooled, HttpServerExchange httpServerExchange) throws IOException { if(httpServerExchange.getRequestMethod().equals(PRI) && connection.getUndertowOptions().get(UndertowOptions.ENABLE_HTTP2, false)) { handleHttp2PriorKnowledge(connection.getChannel(), connection, pooled); return false; } else { sendBadRequestAndClose(connection.getChannel(), new IOException()); return true; } }
@Override protected StreamSinkConduit getSinkConduit(HttpServerExchange exchange, StreamSinkConduit conduit) { if(exchange.getRequestMethod().equals(Methods.CONNECT) && !connectHandled) { //make sure that any unhandled CONNECT requests result in a connection close exchange.setPersistent(false); exchange.getResponseHeaders().put(Headers.CONNECTION, "close"); } return HttpTransferEncoding.createSinkConduit(exchange); }
public ChallengeResult sendChallenge(final HttpServerExchange exchange, final SecurityContext securityContext) { if (exchange.getRequestPath().endsWith(postLocation) && exchange.getRequestMethod().equals(Methods.POST)) { UndertowLogger.SECURITY_LOGGER.debugf("Serving form auth error page %s for %s", loginPage, exchange); // This method would no longer be called if authentication had already occurred. Integer code = servePage(exchange, errorPage); return new ChallengeResult(true, code); } else { UndertowLogger.SECURITY_LOGGER.debugf("Serving login form %s for %s", loginPage, exchange); // we need to store the URL storeInitialLocation(exchange); // TODO - Rather than redirecting, in order to make this mechanism compatible with the other mechanisms we need to // return the actual error page not a redirect. Integer code = servePage(exchange, loginPage); return new ChallengeResult(true, code); } }