@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if (HttpContinue.requiresContinueResponse(exchange)) { exchange.addRequestWrapper(WRAPPER); } handler.handleRequest(exchange); }
@Override public void awaitReadable(final long time, final TimeUnit timeUnit) throws IOException { if (exchange.getStatusCode() == StatusCodes.EXPECTATION_FAILED) { //rejected return; } if (!sent) { sent = true; response = HttpContinue.createResponseSender(exchange); } long exitTime = System.currentTimeMillis() + timeUnit.toMillis(time); if (response != null) { while (!response.send()) { long currentTime = System.currentTimeMillis(); if (currentTime > exitTime) { return; } response.awaitWritable(exitTime - currentTime, TimeUnit.MILLISECONDS); } response = null; } long currentTime = System.currentTimeMillis(); super.awaitReadable(exitTime - currentTime, TimeUnit.MILLISECONDS); }
/** * Sends a continuation using async IO, and calls back when it is complete. * * @param exchange The exchange * @param callback The completion callback */ public static void sendContinueResponse(final HttpServerExchange exchange, final IoCallback callback) { if (!exchange.isResponseChannelAvailable()) { callback.onException(exchange, null, UndertowMessages.MESSAGES.cannotSendContinueResponse()); return; } internalSendContinueResponse(exchange, callback); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if(HttpContinue.requiresContinueResponse(exchange)) { if(accept.resolve(exchange)) { HttpContinue.sendContinueResponse(exchange, new IoCallback() { @Override public void onComplete(final HttpServerExchange exchange, final Sender sender) { exchange.dispatch(next); } @Override public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) { UndertowLogger.REQUEST_IO_LOGGER.ioException(exception); exchange.endExchange(); } }); } else { HttpContinue.rejectExchange(exchange); } } else { next.handleRequest(exchange); } }
HttpContinue.markContinueResponseSent(exchange);
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if(HttpContinue.requiresContinueResponse(exchange)) { if(accept.resolve(exchange)) { HttpContinue.sendContinueResponse(exchange, new IoCallback() { @Override public void onComplete(final HttpServerExchange exchange, final Sender sender) { exchange.dispatch(next); } @Override public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) { UndertowLogger.REQUEST_IO_LOGGER.ioException(exception); exchange.endExchange(); } }); } else { HttpContinue.rejectExchange(exchange); } } else { next.handleRequest(exchange); } }
HttpContinue.markContinueResponseSent(exchange);
/** * Returns true if this exchange requires the server to send a 100 (Continue) response. * * @param exchange The exchange * @return <code>true</code> if the server needs to send a continue response */ public static boolean requiresContinueResponse(final HttpServerExchange exchange) { if (!COMPATIBLE_PROTOCOLS.contains(exchange.getProtocol()) || exchange.isResponseStarted() || !exchange.getConnection().isContinueResponseSupported() || exchange.getAttachment(ALREADY_SENT) != null) { return false; } HeaderMap requestHeaders = exchange.getRequestHeaders(); return requiresContinueResponse(requestHeaders); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if(HttpContinue.requiresContinueResponse(exchange)) { if(accept.resolve(exchange)) { HttpContinue.sendContinueResponse(exchange, new IoCallback() { @Override public void onComplete(final HttpServerExchange exchange, final Sender sender) { exchange.dispatch(next); } @Override public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) { UndertowLogger.REQUEST_IO_LOGGER.ioException(exception); exchange.endExchange(); } }); } else { HttpContinue.rejectExchange(exchange); } } else { next.handleRequest(exchange); } }
@Override public int read(final ByteBuffer dst) throws IOException { if (exchange.getStatusCode() == StatusCodes.EXPECTATION_FAILED) { //rejected return -1; } if (!sent) { sent = true; response = HttpContinue.createResponseSender(exchange); } if (response != null) { if (!response.send()) { return 0; } response = null; } return super.read(dst); }
/** * Sends a continuation using async IO, and calls back when it is complete. * * @param exchange The exchange * @param callback The completion callback */ public static void sendContinueResponse(final HttpServerExchange exchange, final IoCallback callback) { if (!exchange.isResponseChannelAvailable()) { callback.onException(exchange, null, UndertowMessages.MESSAGES.cannotSendContinueResponse()); return; } internalSendContinueResponse(exchange, callback); }
HttpContinue.markContinueResponseSent(exchange);
@Override public void terminateRequestChannel(HttpServerExchange exchange) { if(HttpContinue.requiresContinueResponse(exchange.getRequestHeaders()) && !continueSent) { if(requestChannel != null) { //can happen on upgrade requestChannel.setIgnoreForceClose(true); requestChannel.close(); //if this request requires a 100-continue and it was not sent we have to reset the stream //we do it in a completion listener though, to make sure the response is sent first exchange.addExchangeCompleteListener(new ExchangeCompletionListener() { @Override public void exchangeEvent(HttpServerExchange exchange, NextListener nextListener) { try { channel.sendRstStream(responseChannel.getStreamId(), Http2Channel.ERROR_CANCEL); } finally { nextListener.proceed(); } } }); } } }
@Override public long transferTo(final long position, final long count, final FileChannel target) throws IOException { if (exchange.getStatusCode() == StatusCodes.EXPECTATION_FAILED) { //rejected return -1; } if (!sent) { sent = true; response = HttpContinue.createResponseSender(exchange); } if (response != null) { if (!response.send()) { return 0; } response = null; } return super.transferTo(position, count, target); }
/** * Sends a continuation using async IO, and calls back when it is complete. * * @param exchange The exchange * @param callback The completion callback */ public static void sendContinueResponse(final HttpServerExchange exchange, final IoCallback callback) { if (!exchange.isResponseChannelAvailable()) { callback.onException(exchange, null, UndertowMessages.MESSAGES.cannotSendContinueResponse()); return; } internalSendContinueResponse(exchange, callback); }
@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 long read(final ByteBuffer[] dsts, final int offs, final int len) throws IOException { if (exchange.getStatusCode() == StatusCodes.EXPECTATION_FAILED) { //rejected return -1; } if (!sent) { sent = true; response = HttpContinue.createResponseSender(exchange); } if (response != null) { if (!response.send()) { return 0; } response = null; } return super.read(dsts, offs, len); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if(!exchange.isRequestComplete() && !HttpContinue.requiresContinueResponse(exchange.getRequestHeaders())) { final StreamSourceChannel channel = exchange.getRequestChannel(); int readBuffers = 0;
@Override public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException { if (exchange.getStatusCode() == StatusCodes.EXPECTATION_FAILED) { //rejected return -1; } if (!sent) { sent = true; response = HttpContinue.createResponseSender(exchange); } if (response != null) { if (!response.send()) { return 0; } response = null; } return super.transferTo(count, throughBuffer, target); }
currentRequest.setResponse(response); if(response.getResponseCode() == StatusCodes.EXPECTATION_FAILED) { if(HttpContinue.requiresContinueResponse(currentRequest.getRequest().getRequestHeaders())) { HttpClientConnection.this.state |= CLOSE_REQ; ConduitStreamSinkChannel sinkChannel = HttpClientConnection.this.connection.getSinkChannel();