Search in sources :

Example 1 with HttpMethod

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

the class ResourceHttpRequestHandlerTests method resourceNotFound.

@Test
public void resourceNotFound() throws Exception {
    for (HttpMethod method : HttpMethod.values()) {
        this.request = new MockHttpServletRequest("GET", "");
        this.response = new MockHttpServletResponse();
        resourceNotFound(method);
    }
}
Also used : MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) HttpMethod(cn.taketoday.http.HttpMethod) MockHttpServletResponse(cn.taketoday.web.mock.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 2 with HttpMethod

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

the class ResourceHttpRequestHandlerTests method resolvePathWithTraversal.

@Test
@DisabledOnOs(OS.WINDOWS)
public void resolvePathWithTraversal() throws Exception {
    for (HttpMethod method : HttpMethod.values()) {
        this.request = new MockHttpServletRequest("GET", "");
        this.response = new MockHttpServletResponse();
        requestContext = new ServletRequestContext(null, request, response);
        testResolvePathWithTraversal(method);
    }
}
Also used : MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) HttpMethod(cn.taketoday.http.HttpMethod) MockHttpServletResponse(cn.taketoday.web.mock.MockHttpServletResponse) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Example 3 with HttpMethod

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

the class FormContentFilterTests method wrapPutPatchAndDeleteOnly.

@Test
public void wrapPutPatchAndDeleteOnly() throws Exception {
    for (HttpMethod method : HttpMethod.values()) {
        MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "/");
        request.setContent("foo=bar".getBytes(StandardCharsets.ISO_8859_1));
        request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1");
        this.filterChain = new MockFilterChain();
        this.filter.doFilter(request, this.response, this.filterChain);
        if (method == HttpMethod.PUT || method == HttpMethod.PATCH || method == HttpMethod.DELETE) {
            assertThat(this.filterChain.getRequest()).isNotSameAs(request);
        } else {
            assertThat(this.filterChain.getRequest()).isSameAs(request);
        }
    }
}
Also used : MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) MockFilterChain(cn.taketoday.web.resource.MockFilterChain) HttpMethod(cn.taketoday.http.HttpMethod) Test(org.junit.jupiter.api.Test)

Example 4 with HttpMethod

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

the class RequestMethodsRequestCondition method matchPreFlight.

/**
 * On a pre-flight request match to the would-be, actual request.
 * Hence empty conditions is a match, otherwise try to match to the HTTP
 * method in the "Access-Control-Request-Method" header.
 */
@Nullable
private RequestMethodsRequestCondition matchPreFlight(RequestContext request) {
    if (getMethods().isEmpty()) {
        return this;
    }
    HttpHeaders headers = request.getHeaders();
    HttpMethod expectedMethod = headers.getAccessControlRequestMethod();
    // TODO expectedMethod maybe null
    Assert.state(expectedMethod != null, "No Access-Control-Request-Method Header");
    return matchRequestMethod(expectedMethod);
}
Also used : HttpHeaders(cn.taketoday.http.HttpHeaders) HttpMethod(cn.taketoday.http.HttpMethod) Nullable(cn.taketoday.lang.Nullable)

Example 5 with HttpMethod

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

the class HttpRequestMethodNotSupportedException method getSupportedHttpMethods.

/**
 * Return the actually supported HTTP methods as {@link HttpMethod} instances,
 * or {@code null} if not known.
 */
@Nullable
public Set<HttpMethod> getSupportedHttpMethods() {
    if (this.supportedMethods == null) {
        return null;
    }
    Set<HttpMethod> supportedMethods = new LinkedHashSet<>(this.supportedMethods.length);
    for (String value : this.supportedMethods) {
        HttpMethod method = HttpMethod.valueOf(value);
        supportedMethods.add(method);
    }
    return supportedMethods;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HttpMethod(cn.taketoday.http.HttpMethod) Nullable(cn.taketoday.lang.Nullable)

Aggregations

HttpMethod (cn.taketoday.http.HttpMethod)29 Test (org.junit.jupiter.api.Test)14 URI (java.net.URI)8 IOException (java.io.IOException)7 Nullable (cn.taketoday.lang.Nullable)5 HttpHeaders (cn.taketoday.http.HttpHeaders)4 HttpRequest (cn.taketoday.http.HttpRequest)4 HttpRequestDecorator (cn.taketoday.http.client.support.HttpRequestDecorator)4 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)4 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)4 ArrayList (java.util.ArrayList)4 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)2 DataBufferUtils (cn.taketoday.core.io.buffer.DataBufferUtils)2 DefaultDataBufferFactory (cn.taketoday.core.io.buffer.DefaultDataBufferFactory)2 HttpStatus (cn.taketoday.http.HttpStatus)2 ReactiveHttpOutputMessage (cn.taketoday.http.ReactiveHttpOutputMessage)2 NonNull (cn.taketoday.lang.NonNull)2 CrossOrigin (cn.taketoday.web.annotation.CrossOrigin)2 CorsConfiguration (cn.taketoday.web.cors.CorsConfiguration)2 MockHttpServletResponse (cn.taketoday.web.mock.MockHttpServletResponse)2