Search in sources :

Example 1 with RequestPath

use of cn.taketoday.http.server.RequestPath in project today-infrastructure by TAKETODAY.

the class WebContentInterceptor method beforeProcess.

@Override
public boolean beforeProcess(RequestContext context, Object handler) {
    checkRequest(context);
    RequestPath path = context.getLookupPath();
    if (ObjectUtils.isNotEmpty(cacheControlMappings)) {
        CacheControl control = lookupCacheControl(path);
        if (control != null) {
            if (log.isTraceEnabled()) {
                log.trace("Applying {}", control);
            }
            applyCacheControl(context, control);
            return true;
        }
    }
    if (ObjectUtils.isNotEmpty(cacheMappings)) {
        Integer cacheSeconds = lookupCacheSeconds(path);
        if (cacheSeconds != null) {
            if (log.isTraceEnabled()) {
                log.trace("Applying cacheSeconds {}", cacheSeconds);
            }
            applyCacheSeconds(context, cacheSeconds);
            return true;
        }
    }
    prepareResponse(context);
    return true;
}
Also used : RequestPath(cn.taketoday.http.server.RequestPath) CacheControl(cn.taketoday.http.CacheControl)

Example 2 with RequestPath

use of cn.taketoday.http.server.RequestPath in project today-framework by TAKETODAY.

the class RequestContext method getLookupPath.

/**
 * @since 4.0
 */
public final RequestPath getLookupPath() {
    RequestPath lookupPath = this.lookupPath;
    if (lookupPath == null) {
        lookupPath = RequestPath.parse(getRequestPath(), getContextPath());
        this.lookupPath = lookupPath;
    }
    return lookupPath;
}
Also used : RequestPath(cn.taketoday.http.server.RequestPath)

Example 3 with RequestPath

use of cn.taketoday.http.server.RequestPath in project today-framework by TAKETODAY.

the class PathVariableMapMethodArgumentResolverTests method resolveArgument.

@Test
public void resolveArgument() throws Throwable {
    applyTemplateVars();
    Map<String, String> uriTemplateVars = new HashMap<>();
    uriTemplateVars.put("name1", "value1");
    uriTemplateVars.put("name2", "value2");
    RequestPath requestPath = RequestPath.parse("/mock/value1/value2", null);
    PathPattern pathPattern = PathPatternParser.defaultInstance.parse("/mock/{name1}/{name2}");
    HandlerMatchingMetadata matchingMetadata = new HandlerMatchingMetadata(new Object(), "/mock", requestPath, pathPattern, PathPatternParser.defaultInstance);
    webRequest.setMatchingMetadata(matchingMetadata);
    Object result = resolver.resolveArgument(webRequest, paramMap);
    assertThat(result).isEqualTo(uriTemplateVars);
}
Also used : RequestPath(cn.taketoday.http.server.RequestPath) PathPattern(cn.taketoday.web.util.pattern.PathPattern) HashMap(java.util.HashMap) HandlerMatchingMetadata(cn.taketoday.web.HandlerMatchingMetadata) Test(org.junit.jupiter.api.Test)

Example 4 with RequestPath

use of cn.taketoday.http.server.RequestPath in project today-framework by TAKETODAY.

the class UrlFilenameViewController method extractOperableUrl.

/**
 * Extract a URL path from the given request,
 * suitable for view name extraction.
 *
 * @param request current HTTP request
 * @return the URL to use for view name extraction
 */
protected String extractOperableUrl(RequestContext request) {
    RequestPath lookupPath = request.getLookupPath();
    String path = lookupPath.pathWithinApplication().value();
    path = removeSemicolonContent ? WebUtils.removeSemicolonContent(path) : path;
    return path;
}
Also used : RequestPath(cn.taketoday.http.server.RequestPath)

Example 5 with RequestPath

use of cn.taketoday.http.server.RequestPath in project today-framework by TAKETODAY.

the class WebContentInterceptor method beforeProcess.

@Override
public boolean beforeProcess(RequestContext request, Object handler) {
    checkRequest(request);
    RequestPath path = request.getLookupPath();
    if (ObjectUtils.isNotEmpty(cacheControlMappings)) {
        CacheControl control = lookupCacheControl(path);
        if (control != null) {
            if (log.isTraceEnabled()) {
                log.trace("Applying {}", control);
            }
            applyCacheControl(request, control);
            return true;
        }
    }
    if (ObjectUtils.isNotEmpty(cacheMappings)) {
        Integer cacheSeconds = lookupCacheSeconds(path);
        if (cacheSeconds != null) {
            if (log.isTraceEnabled()) {
                log.trace("Applying cacheSeconds {}", cacheSeconds);
            }
            applyCacheSeconds(request, cacheSeconds);
            return true;
        }
    }
    prepareResponse(request);
    return true;
}
Also used : RequestPath(cn.taketoday.http.server.RequestPath) CacheControl(cn.taketoday.http.CacheControl)

Aggregations

RequestPath (cn.taketoday.http.server.RequestPath)15 PathPattern (cn.taketoday.web.util.pattern.PathPattern)6 HandlerMatchingMetadata (cn.taketoday.web.HandlerMatchingMetadata)4 CacheControl (cn.taketoday.http.CacheControl)2 MockServletRequestContext (cn.taketoday.web.servlet.MockServletRequestContext)2 PathMatchInfo (cn.taketoday.web.util.pattern.PathMatchInfo)2 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)1 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1