@Override public void doScope( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (target.equals("/") && request.getMethod().equals(HttpMethod.POST.asString())) { super.doScope(target, baseRequest, request, response); } } };
final GzipHandler gzipHandler = context.getGzipHandler(); gzipHandler.addIncludedPaths("/*"); gzipHandler.addIncludedMethods(HttpMethod.POST.asString());
@Override public Request method(HttpMethod method) { return method(method.asString()); }
@Override public void init( FilterConfig config ) throws ServletException { super.init( config ); _methods.add( HttpMethod.POST.asString() ); Log.info( "Installed response compression filter" ); } };
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { String method = request.getMethod(); if ( !method.equals(HttpMethod.GET.asString()) && !method.equals(HttpMethod.POST.asString()) && !method.equals(HttpMethod.HEAD.asString()) ) return ; response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ; response.setHeader(HttpNames.hCacheControl, "must-revalidate,no-cache,no-store"); response.setHeader(HttpNames.hPragma, "no-cache"); int code = response.getStatus() ; String message=(response instanceof Response)?((Response)response).getReason(): HttpSC.getMessage(code) ; response.getOutputStream().print(format("Error %d: %s\n", code, message)) ; } }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { String method = request.getMethod(); if ( !method.equals(HttpMethod.GET.asString()) && !method.equals(HttpMethod.POST.asString()) && !method.equals(HttpMethod.HEAD.asString()) ) return ; response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ; ServletOps.setNoCache(response) ; int code = response.getStatus() ; String message=(response instanceof Response)?((Response)response).getReason(): HttpSC.getMessage(code) ; response.getOutputStream().print(format("Error %d: %s\n", code, message)) ; } }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { String method = request.getMethod(); if ( !method.equals(HttpMethod.GET.asString()) && !method.equals(HttpMethod.POST.asString()) && !method.equals(HttpMethod.HEAD.asString()) ) return ; response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ; response.setHeader(HttpNames.hCacheControl, "must-revalidate,no-cache,no-store"); response.setHeader(HttpNames.hPragma, "no-cache"); int code = response.getStatus() ; String message=(response instanceof Response)?((Response)response).getReason(): HttpSC.getMessage(code) ; response.getOutputStream().print(format("Error %d: %s\n", code, message)) ; } }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { String method = request.getMethod(); if ( !method.equals(HttpMethod.GET.asString()) && !method.equals(HttpMethod.POST.asString()) && !method.equals(HttpMethod.HEAD.asString()) ) return ; response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ; response.setHeader(HttpNames.hCacheControl, "must-revalidate,no-cache,no-store"); response.setHeader(HttpNames.hPragma, "no-cache"); int code = response.getStatus() ; String message=(response instanceof Response)?((Response)response).getReason(): HttpSC.getMessage(code) ; response.getOutputStream().print(format("Error %d: %s\n", code, message)) ; } }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { String method = request.getMethod(); if ( !method.equals(HttpMethod.GET.asString()) && !method.equals(HttpMethod.POST.asString()) && !method.equals(HttpMethod.HEAD.asString()) ) return ; response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ; ServletOps.setNoCache(response) ; int code = response.getStatus() ; String message=(response instanceof Response)?((Response)response).getReason(): HttpSC.getMessage(code) ; response.getOutputStream().print(format("Error %d: %s\n", code, message)) ; } }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { String method = request.getMethod(); if ( !method.equals(HttpMethod.GET.asString()) && !method.equals(HttpMethod.POST.asString()) && !method.equals(HttpMethod.HEAD.asString()) ) return ; response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ; ServletOps.setNoCache(response) ; ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024) ; try ( Writer writer = IO.asUTF8(bytes) ) { String reason = (response instanceof Response) ? ((Response)response).getReason() : null; handleErrorPage(request, writer, response.getStatus(), reason) ; writer.flush(); response.setContentLength(bytes.size()) ; response.getOutputStream().write(bytes.toByteArray()) ; } }
/** * Optimized lookup to find a method name and trailing space in a byte array. * @param buffer buffer containing ISO-8859-1 characters, it is not modified. * @return A HttpMethod if a match or null if no easy match. */ public static HttpMethod lookAheadGet(ByteBuffer buffer) { if (buffer.hasArray()) return lookAheadGet(buffer.array(),buffer.arrayOffset()+buffer.position(),buffer.arrayOffset()+buffer.limit()); int l = buffer.remaining(); if (l>=4) { HttpMethod m = CACHE.getBest(buffer,0,l); if (m!=null) { int ml = m.asString().length(); if (l>ml && buffer.get(buffer.position()+ml)==' ') return m; } } return null; }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { String method = request.getMethod(); if ( !method.equals(HttpMethod.GET.asString()) && !method.equals(HttpMethod.POST.asString()) && !method.equals(HttpMethod.HEAD.asString()) ) return ; response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ; ServletOps.setNoCache(response) ; ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024) ; try ( Writer writer = IO.asUTF8(bytes) ) { String reason = (response instanceof Response) ? ((Response)response).getReason() : null; handleErrorPage(request, writer, response.getStatus(), reason) ; writer.flush(); response.setContentLength(bytes.size()) ; response.getOutputStream().write(bytes.toByteArray()) ; } }
@Override public void customize(final Server server) { try { Class.forName("org.eclipse.jetty.server.handler.gzip.GzipHandler"); } catch (final ClassNotFoundException ignored) { log.debug("org.eclipse.jetty.server.handler.gzip.GzipHandler is not in classpath.", ignored); return; } final HandlerCollection handlers = new HandlerCollection(); final GzipHandler gzipHandler = new GzipHandler(); gzipHandler.addIncludedMethods(HttpMethod.GET.asString(), HttpMethod.POST.asString(), HttpMethod.PUT.asString(), HttpMethod.DELETE.asString()); gzipHandler.setCompressionLevel(5); handlers.addHandler(gzipHandler); asList(server.getHandlers()).forEach(handlers::addHandler); server.setHandler(handlers); } }
@Override public void customize(final Server server) { try { Class.forName("org.eclipse.jetty.server.handler.gzip.GzipHandler"); } catch (final ClassNotFoundException ignored) { log.debug("org.eclipse.jetty.server.handler.gzip.GzipHandler is not in classpath.", ignored); return; } final HandlerCollection handlers = new HandlerCollection(); final GzipHandler gzipHandler = new GzipHandler(); gzipHandler.addIncludedMethods(HttpMethod.GET.asString(), HttpMethod.POST.asString(), HttpMethod.PUT.asString(), HttpMethod.DELETE.asString()); gzipHandler.setCompressionLevel(5); handlers.addHandler(gzipHandler); asList(server.getHandlers()).forEach(handlers::addHandler); server.setHandler(handlers); } }
public BufferedResponseHandler() { // include only GET requests _methods.include(HttpMethod.GET.asString()); // Exclude images, aduio and video from buffering for (String type:MimeTypes.getKnownMimeTypes()) { if (type.startsWith("image/")|| type.startsWith("audio/")|| type.startsWith("video/")) _mimeTypes.exclude(type); } LOG.debug("{} mime types {}",this,_mimeTypes); }
private LRSResponse deleteDocument(String resource, Map<String, String> queryParams) { HTTPRequest request = new HTTPRequest(); request.setMethod(HttpMethod.DELETE.asString()); request.setResource(resource); request.setQueryParams(queryParams); HTTPResponse response = makeSyncRequest(request); LRSResponse lrsResponse = new LRSResponse(request, response); if (response.getStatus() == 204) { lrsResponse.setSuccess(true); } else { lrsResponse.setSuccess(false); } return lrsResponse; }
private LRSResponse saveDocument(String resource, Map<String, String> queryParams, Document document) { HTTPRequest request = new HTTPRequest(); request.setMethod(HttpMethod.PUT.asString()); request.setResource(resource); request.setQueryParams(queryParams); request.setContentType(document.getContentType()); request.setContent(document.getContent()); if (document.getEtag() != null) { request.setHeaders(new HashMap<String, String>()); request.getHeaders().put("If-Match", document.getEtag()); } HTTPResponse response = makeSyncRequest(request); LRSResponse lrsResponse = new LRSResponse(request, response); if (response.getStatus() == 204) { lrsResponse.setSuccess(true); } else { lrsResponse.setSuccess(false); } return lrsResponse; }
private LRSResponse updateDocument(String resource, Map<String, String> queryParams, Document document) { HTTPRequest request = new HTTPRequest(); request.setMethod(HttpMethod.POST.asString()); request.setResource(resource); request.setQueryParams(queryParams); request.setContentType(document.getContentType()); request.setContent(document.getContent()); if (document.getEtag() != null) { request.setHeaders(new HashMap<String, String>()); request.getHeaders().put("If-Match", document.getEtag()); } HTTPResponse response = makeSyncRequest(request); LRSResponse lrsResponse = new LRSResponse(request, response); if (response.getStatus() == 204) { lrsResponse.setSuccess(true); } else { lrsResponse.setSuccess(false); } return lrsResponse; }