/** * Marks a continue response as already having been sent. In general this should only be used * by low level handlers than need fine grained control over the continue response. * * @param exchange The exchange */ public static void markContinueResponseSent(HttpServerExchange exchange) { exchange.putAttachment(ALREADY_SENT, true); }
@Override public void handleTrailers(HeaderMap headerMap) { exchange.putAttachment(HttpAttachments.REQUEST_TRAILERS, headerMap); } });
@Override public <T> T putAttachment(AttachmentKey<T> key, T value) { return exchange.putAttachment(key, value); }
@Override public <T> void putAttachment(final AttachmentKey<T> key, final T value) { exchange.putAttachment(key, value); }
/** * Sets the HTTP reason phrase. Depending on the protocol this may or may not be honoured. In particular HTTP2 * has removed support for the reason phrase. * * This method should only be used to interact with legacy frameworks that give special meaning to the reason phrase. * * @param message The status message * @return this exchange */ public HttpServerExchange setReasonPhrase(String message) { putAttachment(REASON_PHRASE, message); return this; }
@Override public void writeAttribute(HttpServerExchange exchange, String newValue) throws ReadOnlyAttributeException { exchange.putAttachment(HttpServerExchange.SECURE_REQUEST, Boolean.parseBoolean(newValue)); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { exchange.putAttachment(key, instance); next.handleRequest(exchange); }
void requestStarted(HttpServerExchange serverExchange) { Long existing = serverExchange.getAttachment(FIRST_REQUEST_ACCESS); if(existing == null) { if (!invalid) { serverExchange.putAttachment(FIRST_REQUEST_ACCESS, System.currentTimeMillis()); } } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.putAttachment(Predicate.PREDICATE_CONTEXT, new TreeMap<String, Object>()); next.handleRequest(exchange); } }
@Override public void terminateWrites() throws IOException { exchange.putAttachment(RESPONSE, outputStream.toByteArray()); outputStream = null; super.terminateWrites(); } }
@Override public int writeFinal(ByteBuffer src) throws IOException { int start = src.position(); int ret = super.writeFinal(src); for (int i = start; i < start + ret; ++i) { outputStream.write(src.get(i)); } if (!src.hasRemaining()) { exchange.putAttachment(RESPONSE, outputStream.toByteArray()); outputStream = null; } return ret; }
@Override public void terminateWrites() throws IOException { //after finish writes all through conduit, it will reach here, at this time, we put response info exchange.putAttachment(RESPONSE, outputStream.toByteArray()); outputStream = null; super.terminateWrites(); } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { exchange.putAttachment(SessionManager.ATTACHMENT_KEY, sessionManager); exchange.putAttachment(SessionConfig.ATTACHMENT_KEY, sessionConfig); final UpdateLastAccessTimeListener handler = new UpdateLastAccessTimeListener(sessionConfig, sessionManager); exchange.addExchangeCompleteListener(handler); next.handleRequest(exchange); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.putAttachment(OLD_RELATIVE_PATH, exchange.getRelativePath()); handler.handleRequest(exchange); } };
@Override public void setSessionId(HttpServerExchange exchange, String sessionId) { exchange.putAttachment(SESSION_ID_SET, Boolean.TRUE); this.config.setSessionId(exchange, this.codec.encode(sessionId)); }
@Override public boolean resolve(final HttpServerExchange value) { final String relativePath = value.getRelativePath(); PathMatcher.PathMatch<Boolean> result = pathMatcher.match(relativePath); boolean matches = Boolean.TRUE.equals(result.getValue()); if(matches) { Map<String, Object> context = value.getAttachment(PREDICATE_CONTEXT); if(context == null) { value.putAttachment(PREDICATE_CONTEXT, context = new TreeMap<>()); } context.put("remaining", result.getRemaining()); } return matches; }
@Override public void completed(final HttpServerExchange exchange, final ProxyConnection connection) { exchange.putAttachment(CONNECTION, connection); exchange.dispatch(SameThreadExecutor.INSTANCE, new ProxyAction(connection, exchange, requestHeaders, rewriteHostHeader, reuseXForwarded, exchange.isRequestComplete() ? this : null, idempotentPredicate)); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { try { handler.handleRequest(exchange); } catch (Throwable throwable) { for (ExceptionHandlerHolder<?> holder : exceptionHandlers) { if (holder.getClazz().isInstance(throwable)) { exchange.putAttachment(THROWABLE, throwable); holder.getHandler().handleRequest(exchange); return; } } throw throwable; } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { FormDataParser parser = formParserFactory.createParser(exchange); if (parser == null) { next.handleRequest(exchange); return; } if(exchange.isBlocking()) { exchange.putAttachment(FormDataParser.FORM_DATA, parser.parseBlocking()); next.handleRequest(exchange); } else { parser.parse(next); } }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { AllowedContentEncodings encodings = contentEncodingRepository.getContentEncodings(exchange); if (encodings == null || !exchange.isResponseChannelAvailable()) { next.handleRequest(exchange); } else if (encodings.isNoEncodingsAllowed()) { noEncodingHandler.handleRequest(exchange); } else { exchange.addResponseWrapper(encodings); exchange.putAttachment(AllowedContentEncodings.ATTACHMENT_KEY, encodings); next.handleRequest(exchange); } }