/** * * @return True if this exchange represents an upgrade response */ public boolean isUpgrade() { return getStatusCode() == StatusCodes.SWITCHING_PROTOCOLS; }
@Override public int statusCode() { return exchange.getStatusCode(); }
@Override public String readAttribute(final HttpServerExchange exchange) { return Integer.toString(exchange.getStatusCode()); }
@Override public HttpStatus getStatusCode() { HttpStatus httpStatus = super.getStatusCode(); return httpStatus != null ? httpStatus : HttpStatus.resolve(this.exchange.getStatusCode()); }
@Override public boolean handleDefaultResponse(final HttpServerExchange exchange) { Set<Integer> codes = responseCodes; if (!exchange.isResponseStarted() && codes.contains(exchange.getStatusCode())) { serveFile(exchange); return true; } return false; } });
public static boolean isEntityBodyAllowed(HttpServerExchange exchange){ int code = exchange.getStatusCode(); return isEntityBodyAllowed(code); }
@Override public String readAttribute(final HttpServerExchange exchange) { return StatusCodes.getReason(exchange.getStatusCode()); }
/** * impl of dumping response status code to result * @param result A map you want to put dump information to */ @Override public void dumpResponse(Map<String, Object> result) { this.statusCodeResult = String.valueOf(exchange.getStatusCode()); this.putDumpInfoTo(result); }
@Override public void exchangeEvent(HttpServerExchange exchange, NextListener nextListener) { long time = System.currentTimeMillis() - start; totalResult.update((int) time, exchange.getStatusCode()); nextListener.proceed(); } });
@Override public HttpStatus getStatusCode() { HttpStatus httpStatus = super.getStatusCode(); return httpStatus != null ? httpStatus : HttpStatus.resolve(this.exchange.getStatusCode()); }
@Override public boolean handleDefaultResponse(final HttpServerExchange exchange) { if (!exchange.isResponseChannelAvailable()) { return false; } Set<Integer> codes = responseCodes; if (codes == null ? exchange.getStatusCode() >= StatusCodes.BAD_REQUEST : codes.contains(Integer.valueOf(exchange.getStatusCode()))) { final String errorPage = "<html><head><title>Error</title></head><body>" + exchange.getStatusCode() + " - " + StatusCodes.getReason(exchange.getStatusCode()) + "</body></html>"; exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, "" + errorPage.length()); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html"); Sender sender = exchange.getResponseSender(); sender.send(errorPage); return true; } return false; } };
@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); }
@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); }
@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); }
@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 protected StreamSinkConduit getSinkConduit(HttpServerExchange exchange, StreamSinkConduit conduit) { HeaderMap headers = responseChannel.getHeaders(); DateUtils.addDateHeaderIfRequired(exchange); headers.add(STATUS, exchange.getStatusCode()); Connectors.flattenCookies(exchange); return originalSinkConduit; }
@Override public void awaitReadable() throws IOException { if (exchange.getStatusCode() == StatusCodes.EXPECTATION_FAILED) { //rejected return; } if (!sent) { sent = true; response = HttpContinue.createResponseSender(exchange); } if (response != null) { while (!response.send()) { response.awaitWritable(); } response = null; } super.awaitReadable(); } }
/** * Send a simple response string. * * @param exchange the http server exchange * @param response the response string */ static void sendResponse(final HttpServerExchange exchange, final String response) { exchange.setStatusCode(StatusCodes.OK); exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, CONTENT_TYPE); final Sender sender = exchange.getResponseSender(); UndertowLogger.ROOT_LOGGER.mcmpSendingResponse(exchange.getSourceAddress(), exchange.getStatusCode(), exchange.getResponseHeaders(), response); sender.send(response); }
@Override public StreamSinkConduit wrap(ConduitFactory<StreamSinkConduit> factory, HttpServerExchange exchange) { HeaderMap headers = newExchange.getResponseHeaders(); DateUtils.addDateHeaderIfRequired(exchange); headers.add(STATUS, exchange.getStatusCode()); Connectors.flattenCookies(exchange); Http2HeadersStreamSinkChannel sink = new Http2HeadersStreamSinkChannel(channel, requestChannel.getStreamId(), headers); StreamSinkChannelWrappingConduit ret = new StreamSinkChannelWrappingConduit(sink); ret.setWriteReadyHandler(new WriteReadyHandler.ChannelListenerHandler(Connectors.getConduitSinkChannel(exchange))); return ret; } });
public CachedHttpRequest(final HttpServerExchange exchange) { this.path = exchange.getRequestPath(); this.etag = ETagUtils.getETag(exchange); this.contentLocation = exchange.getResponseHeaders().getFirst(Headers.CONTENT_LOCATION); this.language = exchange.getResponseHeaders().getFirst(Headers.CONTENT_LANGUAGE); this.contentType = exchange.getResponseHeaders().getFirst(Headers.CONTENT_TYPE); String lmString = exchange.getResponseHeaders().getFirst(Headers.LAST_MODIFIED); if (lmString == null) { this.lastModified = null; } else { this.lastModified = DateUtils.parseDate(lmString); } //the content encoding can be decided dynamically, based on the current state of the request //as the decision to compress generally depends on size and mime type final AllowedContentEncodings encoding = exchange.getAttachment(AllowedContentEncodings.ATTACHMENT_KEY); if(encoding != null) { this.contentEncoding = encoding.getCurrentContentEncoding(); } else { this.contentEncoding = exchange.getResponseHeaders().getFirst(Headers.CONTENT_ENCODING); } this.responseCode = exchange.getStatusCode(); }