Search in sources :

Example 11 with Response

use of core.framework.web.Response in project core-ng-project by neowu.

the class StaticFileController method execute.

@Override
public Response execute(Request request) {
    logger.debug("requestFile={}", contentFile);
    Response response = Response.file(contentFile);
    if (contentType != null)
        response.contentType(contentType);
    if (cacheHeader != null)
        response.header(HTTPHeaders.CACHE_CONTROL, cacheHeader);
    return response;
}
Also used : Response(core.framework.web.Response)

Example 12 with Response

use of core.framework.web.Response in project core-ng-project by neowu.

the class WebSecurityInterceptor method intercept.

@Override
public Response intercept(Invocation invocation) throws Exception {
    Request request = invocation.context().request();
    if (!"https".equals(request.scheme())) {
        return Response.redirect(redirectURL(request), HTTPStatus.MOVED_PERMANENTLY);
    } else {
        Response response = invocation.proceed();
        response.header("Strict-Transport-Security", "max-age=31536000");
        response.contentType().ifPresent(contentType -> {
            if (ContentType.TEXT_HTML.mediaType().equals(contentType.mediaType())) {
                response.header("X-Frame-Options", "DENY");
                response.header("X-XSS-Protection", "1; mode=block");
            }
            response.header("X-Content-Type-Options", "nosniff");
        });
        return response;
    }
}
Also used : Response(core.framework.web.Response) Request(core.framework.web.Request)

Example 13 with Response

use of core.framework.web.Response in project core-ng-project by neowu.

the class StaticDirectoryController method execute.

@Override
public Response execute(Request request) {
    String path = request.pathParam("path");
    Path filePath = contentDirectory.resolve(path);
    logger.debug("requestFile={}", filePath);
    if (!Files.isRegularFile(filePath, LinkOption.NOFOLLOW_LINKS) || !filePath.startsWith(contentDirectory))
        throw new NotFoundException("not found, path=" + request.path());
    Response response = Response.file(filePath);
    ContentType contentType = MimeTypes.get(filePath.getFileName().toString());
    if (contentType != null)
        response.contentType(contentType);
    if (cacheHeader != null)
        response.header(HTTPHeaders.CACHE_CONTROL, cacheHeader);
    return response;
}
Also used : Path(java.nio.file.Path) Response(core.framework.web.Response) ContentType(core.framework.http.ContentType) NotFoundException(core.framework.web.exception.NotFoundException)

Aggregations

Response (core.framework.web.Response)13 Test (org.junit.jupiter.api.Test)6 Controller (core.framework.web.Controller)4 Request (core.framework.web.Request)4 Interceptor (core.framework.web.Interceptor)2 Protected (app.web.interceptor.Protected)1 PathParam (core.framework.api.web.service.PathParam)1 ContentType (core.framework.http.ContentType)1 CodeBuilder (core.framework.impl.asm.CodeBuilder)1 ActionLog (core.framework.impl.log.ActionLog)1 RequestImpl (core.framework.impl.web.request.RequestImpl)1 ResponseImpl (core.framework.impl.web.response.ResponseImpl)1 ErrorResponse (core.framework.impl.web.service.ErrorResponse)1 NotFoundException (core.framework.web.exception.NotFoundException)1 HeaderMap (io.undertow.util.HeaderMap)1 HttpString (io.undertow.util.HttpString)1 Type (java.lang.reflect.Type)1 Path (java.nio.file.Path)1 Optional (java.util.Optional)1