content.append(routeContext.getRequestMethod()).append(' ').append(routeContext.getRequestUri()); content.append('\''); content.append('\n');
routeContext.getResponse().contentLength(file.length()); URL url = requestedPath.toUri().toURL(); switch (routeContext.getRequestMethod()) { case HttpConstants.Method.HEAD: setResponseHeaders(url, routeContext); default: log.warn("Unsupported request method {} for {}", routeContext.getRequestMethod(), routeContext.getRequestUri());
protected void processRouteInterceptors(RouteContext routeContext) { if (interceptors.isEmpty()) { return; } List<RouteMatch> chain = new ArrayList<>(); for (RouteHandler interceptor : interceptors) { // create a route for interceptor Route route = new Route(routeContext.getRequestMethod(), routeContext.getRequestUri(), interceptor); route.setName(StringUtils.format("{}<{}>", Interceptor.class.getSimpleName(), route.getRouteHandler().getClass().getSimpleName())); route.bindAll(routeContext.getRoute().getAttributes()); // add route in chain RouteMatch match = new RouteMatch(route, null); chain.add(match); } // TODO DefaultRouteContext is hardcoded RouteContext context = new DefaultRouteContext(routeContext.getApplication(), routeContext.getRequest(), routeContext.getResponse(), chain); context.next(); }
contentType = StringUtils.getPrefix(contentType, ';').trim(); if (!guardedTypes.contains(contentType)) { log.debug("Ignoring '{}' request for {} '{}'", contentType, context.getRequestMethod(), context.getRequestUri()); return; log.debug("Ignoring 'nocheck' request for {} '{}'", context.getRequestMethod(), context.getRequestUri()); return; log.debug("Validated '{}' for {} '{}'", TOKEN, context.getRequestMethod(), context.getRequestUri()); String token = CryptoUtils.hmacDigest(sessionId, secretKey, algorithm); setSessionCsrfToken(context, token); log.debug("Generated '{}' for {} '{}'", TOKEN, context.getRequestMethod(), context.getRequestUri());
@Override public void handle(RouteContext context) { final Response response = context.getResponse(); response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_ORIGIN, allowOrigin); if (exposeHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_EXPOSE_HEADERS, exposeHeaders); } if (maxAge != -1) { response.header(HttpConstants.Header.ACCESS_CONTROL_MAX_AGE, "" + maxAge); } // According to the documentation only if true is what needs to be set // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials#Directives if (allowCredentials) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); } if (allowMethods != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_METHODS, allowMethods); } if (allowHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_HEADERS, allowHeaders); } if (context.getRequestMethod().equals("OPTIONS")) { response.accepted(); return; } context.next(); }
/** * Prepares an Error instance for the error response. * * @param statusCode * @param routeContext * @return an Error */ protected Error prepareError(int statusCode, RouteContext routeContext) { String messageKey = "pippo.statusCode" + statusCode; Error error = new Error(); error.setStatusCode(statusCode); error.setStatusMessage(application.getMessages().get(messageKey, routeContext)); error.setRequestMethod(routeContext.getRequestMethod()); error.setRequestUri(routeContext.getRequestUri()); error.setStacktrace(routeContext.getLocal(STACKTRACE)); error.setMessage(routeContext.getLocal(MESSAGE)); return error; }
protected void serveSpecification(RouteContext ctx, String specificationName) { String extension = Files.getFileExtension(specificationName); if (extension.isEmpty()) { // default to json specificationName += ".json"; } final String finalDocumentName = specificationName; final String finalExtension = Files.getFileExtension(finalDocumentName); String document = specifications.get(finalDocumentName.toLowerCase()); if (document == null) { ctx.getResponse().notFound(); } else { ctx.getResponse().ok(); httpCacheToolkit.addEtag(ctx, startTime); if ("json".equals(finalExtension)) { ctx.json(); } else if ("yaml".equals(finalExtension)) { ctx.yaml(); } else { ctx.text(); } if (HttpMethod.GET.equals(ctx.getRequestMethod())) { ctx.getResponse().send(document); } } }
protected void serveSpecification(RouteContext ctx, String specificationName) { String extension = Files.getFileExtension(specificationName); if (extension.isEmpty()) { // default to json specificationName += ".json"; } final String finalDocumentName = specificationName; final String finalExtension = Files.getFileExtension(finalDocumentName); String document = specifications.get(finalDocumentName.toLowerCase()); if (document == null) { ctx.getResponse().notFound(); } else { ctx.getResponse().ok(); httpCacheToolkit.addEtag(ctx, startTime); if ("json".equals(finalExtension)) { ctx.json(); } else if ("yaml".equals(finalExtension)) { ctx.yaml(); } else { ctx.text(); } if (HttpMethod.GET.equals(ctx.getRequestMethod())) { ctx.getResponse().send(document); } } }
protected void processRouteInterceptors(RouteContext routeContext) { if (interceptors.isEmpty()) { return; } List<RouteMatch> chain = new ArrayList<>(); for (RouteHandler interceptor : interceptors) { // create a route for interceptor Route route = new Route(routeContext.getRequestMethod(), routeContext.getRequestUri(), interceptor); route.setName(StringUtils.format("{}<{}>", Interceptor.class.getSimpleName(), route.getRouteHandler().getClass().getSimpleName())); route.bindAll(routeContext.getRoute().getAttributes()); // add route in chain RouteMatch match = new RouteMatch(route, null); chain.add(match); } // TODO DefaultRouteContext is hardcoded RouteContext context = new DefaultRouteContext(routeContext.getApplication(), routeContext.getRequest(), routeContext.getResponse(), chain); context.next(); }