use of org.springframework.http.HttpMethod in project spring-framework by spring-projects.
the class AbstractRequestExpectationManager method createUnexpectedRequestError.
/**
* Return an {@code AssertionError} that a sub-class can raise for an
* unexpected request.
*/
protected AssertionError createUnexpectedRequestError(ClientHttpRequest request) {
HttpMethod method = request.getMethod();
URI uri = request.getURI();
String message = "No further requests expected: HTTP " + method + " " + uri + "\n";
return new AssertionError(message + getRequestDetails());
}
use of org.springframework.http.HttpMethod in project spring-framework by spring-projects.
the class HttpHandlerConnector method adaptRequest.
private ServerHttpRequest adaptRequest(MockClientHttpRequest request, Publisher<DataBuffer> body) {
HttpMethod method = request.getMethod();
URI uri = request.getURI();
HttpHeaders headers = request.getHeaders();
MultiValueMap<String, HttpCookie> cookies = request.getCookies();
return MockServerHttpRequest.method(method, uri).headers(headers).cookies(cookies).body(body);
}
use of org.springframework.http.HttpMethod in project spring-framework by spring-projects.
the class DefaultCorsProcessor method handleInternal.
/**
* Handle the given request.
*/
protected boolean handleInternal(ServerWebExchange exchange, CorsConfiguration config, boolean preFlightRequest) {
ServerHttpRequest request = exchange.getRequest();
ServerHttpResponse response = exchange.getResponse();
String requestOrigin = request.getHeaders().getOrigin();
String allowOrigin = checkOrigin(config, requestOrigin);
HttpMethod requestMethod = getMethodToUse(request, preFlightRequest);
List<HttpMethod> allowMethods = checkMethods(config, requestMethod);
List<String> requestHeaders = getHeadersToUse(request, preFlightRequest);
List<String> allowHeaders = checkHeaders(config, requestHeaders);
if (allowOrigin == null || allowMethods == null || (preFlightRequest && allowHeaders == null)) {
rejectRequest(response);
return false;
}
HttpHeaders responseHeaders = response.getHeaders();
responseHeaders.setAccessControlAllowOrigin(allowOrigin);
responseHeaders.add(HttpHeaders.VARY, HttpHeaders.ORIGIN);
if (preFlightRequest) {
responseHeaders.setAccessControlAllowMethods(allowMethods);
}
if (preFlightRequest && !allowHeaders.isEmpty()) {
responseHeaders.setAccessControlAllowHeaders(allowHeaders);
}
if (!CollectionUtils.isEmpty(config.getExposedHeaders())) {
responseHeaders.setAccessControlExposeHeaders(config.getExposedHeaders());
}
if (Boolean.TRUE.equals(config.getAllowCredentials())) {
responseHeaders.setAccessControlAllowCredentials(true);
}
if (preFlightRequest && config.getMaxAge() != null) {
responseHeaders.setAccessControlMaxAge(config.getMaxAge());
}
return true;
}
use of org.springframework.http.HttpMethod in project spring-framework by spring-projects.
the class InterceptingClientHttpRequestFactoryTests method changeMethod.
@Test
public void changeMethod() throws Exception {
final HttpMethod changedMethod = HttpMethod.POST;
ClientHttpRequestInterceptor interceptor = new ClientHttpRequestInterceptor() {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
return execution.execute(new HttpRequestWrapper(request) {
@Override
public HttpMethod getMethod() {
return changedMethod;
}
}, body);
}
};
requestFactoryMock = new RequestFactoryMock() {
@Override
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
assertEquals(changedMethod, httpMethod);
return super.createRequest(uri, httpMethod);
}
};
requestFactory = new InterceptingClientHttpRequestFactory(requestFactoryMock, Collections.singletonList(interceptor));
ClientHttpRequest request = requestFactory.createRequest(new URI("http://example.com"), HttpMethod.GET);
request.execute();
}
use of org.springframework.http.HttpMethod in project spring-framework by spring-projects.
the class AsyncRestTemplateIntegrationTests method optionsForAllow.
@Test
public void optionsForAllow() throws Exception {
Future<Set<HttpMethod>> allowedFuture = template.optionsForAllow(new URI(baseUrl + "/get"));
Set<HttpMethod> allowed = allowedFuture.get();
assertEquals("Invalid response", EnumSet.of(HttpMethod.GET, HttpMethod.OPTIONS, HttpMethod.HEAD, HttpMethod.TRACE), allowed);
}
Aggregations