@Test public void testOverrideFromHeader() throws Exception { HttpServerExchange exchange = new HttpServerExchange(null); exchange.setRequestMethod(Methods.POST); exchange.getRequestHeaders().put(MethodOverrideHandler.HEADER, "CONNECT"); this.target.handleRequest(exchange); assertEquals(Methods.CONNECT, exchange.getRequestMethod()); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if (Methods.POST.equals(exchange.getRequestMethod())) { String newMethod = exchange.getRequestHeaders().getFirst(HEADER); Optional<HttpString> opt = HttpMethod.find(newMethod); if (opt.isPresent()) { exchange.setRequestMethod(opt.get()); } else { FormData data = exchange .getAttachment(FormDataParser.FORM_DATA); if (data != null) { FormData.FormValue fv = data.getFirst(FORM); if (fv != null && fv.isFile() == false) { HttpMethod.find(fv.getValue()).map( exchange::setRequestMethod); } } } } this.next.handleRequest(exchange); }
MethodOverrideHandler implements HttpHandler { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { if (Methods.POST.equals(exchange.getRequestMethod())) { String newMethod = exchange.getRequestHeaders().getFirst(HEADER); Optional<HttpString> opt = HttpMethod.find(newMethod); if (opt.isPresent()) { exchange.setRequestMethod(opt.get()); } else { FormData data = exchange .getAttachment(FormDataParser.FORM_DATA); if (data != null) { FormData.FormValue fv = data.getFirst(FORM); if (fv != null && fv.isFile() == false) { HttpMethod.find(fv.getValue()).map( exchange::setRequestMethod); } } } } this.next.handleRequest(exchange); } }
MethodOverrideHandler implements HttpHandler { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { if (Methods.POST.equals(exchange.getRequestMethod())) { String newMethod = exchange.getRequestHeaders().getFirst(HEADER); Optional<HttpString> opt = HttpMethod.find(newMethod); if (opt.isPresent()) { exchange.setRequestMethod(opt.get()); } else { FormData data = exchange .getAttachment(FormDataParser.FORM_DATA); if (data != null) { FormData.FormValue fv = data.getFirst(FORM); if (fv != null && fv.isFile() == false) { HttpMethod.find(fv.getValue()).map( exchange::setRequestMethod); } } } } this.next.handleRequest(exchange); } MethodOverrideHandler(HttpHandler next); }
MethodOverrideHandler implements HttpHandler { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { if (Methods.POST.equals(exchange.getRequestMethod())) { String newMethod = exchange.getRequestHeaders().getFirst(HEADER); Optional<HttpString> opt = HttpMethod.find(newMethod); if (opt.isPresent()) { exchange.setRequestMethod(opt.get()); } else { FormData data = exchange .getAttachment(FormDataParser.FORM_DATA); if (data != null) { FormData.FormValue fv = data.getFirst(FORM); if (fv != null && fv.isFile() == false) { HttpMethod.find(fv.getValue()).map( exchange::setRequestMethod); } } } } this.next.handleRequest(exchange); } MethodOverrideHandler(HttpHandler next); @Override void handleRequest(HttpServerExchange exchange); }
MethodOverrideHandler implements HttpHandler { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { if (Methods.POST.equals(exchange.getRequestMethod())) { String newMethod = exchange.getRequestHeaders().getFirst(HEADER); Optional<HttpString> opt = HttpMethod.find(newMethod); if (opt.isPresent()) { exchange.setRequestMethod(opt.get()); } else { FormData data = exchange .getAttachment(FormDataParser.FORM_DATA); if (data != null) { FormData.FormValue fv = data.getFirst(FORM); if (fv != null && fv.isFile() == false) { HttpMethod.find(fv.getValue()).map( exchange::setRequestMethod); } } } } this.next.handleRequest(exchange); } MethodOverrideHandler(HttpHandler next); @Override void handleRequest(HttpServerExchange exchange);  }