/** * Determine whether this request conforms to HTTP 0.9. * * @return {@code true} if the request protocol is equal to {@link Protocols#HTTP_0_9}, {@code false} otherwise */ public boolean isHttp09() { return protocol.equals(Protocols.HTTP_0_9); }
/** * Determine whether this request conforms to HTTP 1.0. * * @return {@code true} if the request protocol is equal to {@link Protocols#HTTP_1_0}, {@code false} otherwise */ public boolean isHttp10() { return protocol.equals(Protocols.HTTP_1_0); }
/** * Determine whether this request conforms to HTTP 1.1. * * @return {@code true} if the request protocol is equal to {@link Protocols#HTTP_1_1}, {@code false} otherwise */ public boolean isHttp11() { return protocol.equals(Protocols.HTTP_1_1); }
@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; }
protected boolean handlesMethod(HttpString method) { if(Methods.GET.equals(method)) { return true; } return super.handlesMethod(method); }
/** * * @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 protected void handleRequest(HttpString method, HttpServerExchange exchange) throws Exception { if (!Methods.GET.equals(method)) { super.handleRequest(method, exchange); return; } // Process the request processRequest(exchange); }
/** * 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; } }
/** * * @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); } } }
private static boolean persistentConnection(HttpServerExchange exchange, String connectionHeader) { if (exchange.isHttp11()) { return !(connectionHeader != null && Headers.CLOSE.equalToString(connectionHeader)); } else if (exchange.isHttp10()) { if (connectionHeader != null) { if (Headers.KEEP_ALIVE.equals(new HttpString(connectionHeader))) { return true; } } } log.trace("Connection not persistent"); return false; }
public static boolean isPreflightedRequest(HttpServerExchange exchange) { return Methods.OPTIONS.equals(exchange.getRequestMethod()) && isCoreRequest(exchange.getRequestHeaders()); } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if (exchange.getRequestMethod().equals(Methods.GET) || exchange.getRequestMethod().equals(Methods.POST)) { serveResource(exchange, true); } else if (exchange.getRequestMethod().equals(Methods.HEAD)) { serveResource(exchange, false); } else { if (KNOWN_METHODS.contains(exchange.getRequestMethod())) { exchange.setStatusCode(StatusCodes.METHOD_NOT_ALLOWED); exchange.getResponseHeaders().add(Headers.ALLOW, String.join(", ", Methods.GET_STRING, Methods.HEAD_STRING, Methods.POST_STRING)); } else { exchange.setStatusCode(StatusCodes.NOT_IMPLEMENTED); } exchange.endExchange(); } }
private boolean isUpgradeOrConnect(HttpServerExchange exchange) { return exchange.isUpgrade() || (exchange.getRequestMethod().equals(Methods.CONNECT) && ((HttpServerConnection)exchange.getConnection()).isConnectHandled() ); }
@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); }
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; } }
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); } }