@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { String method = request.getMethod(); if (!HttpMethod.GET.is(method) && !HttpMethod.POST.is(method) && !HttpMethod.HEAD.is(method)) { request = new ErrorHttpServletRequest(request); } this.delegate.handle(target, baseRequest, request, response); }
session.setAttribute(__J_METHOD, request.getMethod()); if (MimeTypes.Type.FORM_ENCODED.is(req.getContentType()) && HttpMethod.POST.is(request.getMethod()))
if (!expired || !HttpMethod.GET.is(request.getMethod())) return new UserAuthentication(getAuthMethod(), identity);
public boolean isHead() { return _metadata!=null && HttpMethod.HEAD.is(_metadata.getMethod()); }
public boolean isHead() { MetaData.Request metadata = _metaData; return metadata!=null && HttpMethod.HEAD.is(metadata.getMethod()); }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (target.equals("/trace.html") && (HttpMethod.POST.is(request.getMethod()))) { baseRequest.setHandled(true); String trace = request.getParameter("trace"); response.getWriter().write(traceHtml(trace)); } }
/** * Parse according to https://tools.ietf.org/html/rfc7230#section-5.3 * @param method the request method * @param uri the request uri */ public void parseRequestTarget(String method,String uri) { clear(); _uri=uri; if (HttpMethod.CONNECT.is(method)) _path=uri; else parse(uri.startsWith("/")?State.PATH:State.START,uri,0,uri.length()); }
/** Parse according to https://tools.ietf.org/html/rfc7230#section-5.3 * @param method * @param uri */ public void parseRequestTarget(String method,String uri) { clear(); _uri=uri; if (HttpMethod.CONNECT.is(method)) _path=uri; else parse(uri.startsWith("/")?State.PATH:State.START,uri,0,uri.length()); }
/** * Parse according to https://tools.ietf.org/html/rfc7230#section-5.3 * @param method the request method * @param uri the request uri */ public void parseRequestTarget(String method,String uri) { clear(); _uri=uri; if (HttpMethod.CONNECT.is(method)) _path=uri; else parse(uri.startsWith("/")?State.PATH:State.START,uri,0,uri.length()); }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (baseRequest.isHandled()) return; if (!HttpMethod.GET.is(request.getMethod()) && !HttpMethod.HEAD.is(request.getMethod())) { // try another handler super.handle(target,baseRequest,request,response); return; } if (_resourceService.doGet(request,response)) baseRequest.setHandled(true); else // no resource - try other handlers super.handle(target,baseRequest,request,response); }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { baseRequest.setHandled(true); String method = request.getMethod(); if(!HttpMethod.GET.is(method) && !HttpMethod.POST.is(method) && !HttpMethod.HEAD.is(method)) return; response.setContentType(MimeTypes.Type.TEXT_HTML_8859_1.asString()); if (_cacheControl!=null) response.setHeader(HttpHeader.CACHE_CONTROL.asString(), _cacheControl); ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096); String reason=(response instanceof Response)?((Response)response).getReason():null; handleErrorPage(request, writer, response.getStatus(), reason); writer.flush(); response.setContentLength(writer.size()); writer.writeTo(response.getOutputStream()); writer.destroy(); }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (HttpMethod.CONNECT.is(request.getMethod())) { logger.debug("CONNECT request for {}", request.getRequestURI()); baseRequest.setHandled(true); ConnectContext connectContext = new ConnectContext(request, response, HttpConnection.getCurrentConnection().getEndPoint()); try { SocketChannel channel = SocketChannel.open(); channel.socket().setTcpNoDelay(true); channel.configureBlocking(false); channel.connect(new InetSocketAddress("127.0.0.1", securePort)); selector.connect(channel, connectContext); } catch (IOException ioe) { connectContext.onConnectFailure(ioe); } } else { super.handle(target, baseRequest, request, response); } }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (HttpMethod.CONNECT.is(request.getMethod())) { String serverAddress = request.getRequestURI(); if (LOG.isDebugEnabled()) LOG.debug("CONNECT request for {}", serverAddress); handleConnect(baseRequest, request, response, serverAddress); } else { super.handle(target, baseRequest, request, response); } }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { baseRequest.setHandled(true); String method = request.getMethod(); if(!HttpMethod.GET.is(method) && !HttpMethod.POST.is(method) && !HttpMethod.HEAD.is(method)) return; response.setContentType(MimeTypes.Type.TEXT_HTML_8859_1.asString()); if (_cacheControl!=null) response.setHeader(HttpHeader.CACHE_CONTROL.asString(), _cacheControl); ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096); String reason=(response instanceof Response)?((Response)response).getReason():null; handleErrorPage(request, writer, response.getStatus(), reason); writer.flush(); response.setContentLength(writer.size()); writer.writeTo(response.getOutputStream()); writer.destroy(); }
@Override public boolean startResponse(HttpVersion version, int status, String reason) { HttpExchange exchange = getHttpExchange(); if (exchange == null) return false; String method = exchange.getRequest().getMethod(); parser.setHeadResponse(HttpMethod.HEAD.is(method) || (HttpMethod.CONNECT.is(method) && status == HttpStatus.OK_200)); exchange.getResponse().version(version).status(status).reason(reason); return !responseBegin(exchange); }
@Override public boolean messageComplete() { HttpExchange exchange = getHttpExchange(); if (exchange == null) return false; int status = exchange.getResponse().getStatus(); if (status != HttpStatus.CONTINUE_100) complete = true; boolean proceed = responseSuccess(exchange); if (!proceed) return true; if (status == HttpStatus.SWITCHING_PROTOCOLS_101) return true; if (HttpMethod.CONNECT.is(exchange.getRequest().getMethod()) && status == HttpStatus.OK_200) return true; return false; }
protected void handleOptions(Request request,Response response) throws IOException { if (!HttpMethod.OPTIONS.is(request.getMethod())) response.sendError(HttpStatus.BAD_REQUEST_400); request.setHandled(true); response.setStatus(200); response.getHttpFields().put(HttpHeader.ALLOW,"GET,POST,HEAD,OPTIONS"); response.setContentLength(0); response.complete(); }
protected void handleOptions(Request request,Response response) throws IOException { if (!HttpMethod.OPTIONS.is(request.getMethod())) response.sendError(HttpStatus.BAD_REQUEST_400); request.setHandled(true); response.setStatus(200); response.getHttpFields().put(HttpHeader.ALLOW,"GET,POST,HEAD,OPTIONS"); response.setContentLength(0); response.complete(); }
public void handle(HttpChannel<?> connection) throws IOException, ServletException { final String target=connection.getRequest().getPathInfo(); final Request request=connection.getRequest(); final Response response=connection.getResponse(); if (LOG.isDebugEnabled()) LOG.debug(request.getDispatcherType()+" "+request.getMethod()+" "+target+" on "+connection); if (HttpMethod.OPTIONS.is(request.getMethod()) || "*".equals(target)) { if (!HttpMethod.OPTIONS.is(request.getMethod())) response.sendError(HttpStatus.BAD_REQUEST_400); handleOptions(request,response); if (!request.isHandled()) handle(target, request, request, response); } else handle(target, request, request, response); if (LOG.isDebugEnabled()) LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus()+" handled="+request.isHandled()); }