Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package io.undertow.server.handlers;
 
A handler that handles HTTP trace requests

Author(s):
Stuart Douglas
public class HttpTraceHandler implements HttpHandler {
    private final HttpHandler handler;
    public HttpTraceHandler(final HttpHandler handler) {
        this. = handler;
    }
    @Override
    public void handleRequest(final HttpServerExchange exchangethrows Exception {
        if(exchange.getRequestMethod().equals(.)) {
            exchange.getResponseHeaders().put(."message/http");
            StringBuilder body = new StringBuilder("TRACE ");
            body.append(exchange.getRequestURI());
            if(!exchange.getQueryString().isEmpty()) {
                body.append('?');
                body.append(exchange.getQueryString());
            }
            body.append(exchange.getProtocol().toString());
            body.append("\r\n");
            for(HeaderValues header : exchange.getRequestHeaders()) {
                for(String value : header) {
                    body.append(header.getHeaderName());
                    body.append(": ");
                    body.append(value);
                    body.append("\r\n");
                }
            }
            body.append("\r\n");
            exchange.getResponseSender().send(body.toString());
        } else {
            .handleRequest(exchange);
        }
    }
New to GrepCode? Check out our FAQ X