use of org.springframework.http.server.reactive.ServerHttpRequest in project spring-framework by spring-projects.
the class RedirectView method createTargetUrl.
/**
* Create the target URL and, if necessary, pre-pend the contextPath, expand
* URI template variables, append the current request query, and apply the
* configured {@link #getRequestDataValueProcessor()
* RequestDataValueProcessor}.
*/
protected final String createTargetUrl(Map<String, Object> model, ServerWebExchange exchange) {
String url = getUrl();
Assert.state(url != null, "'url' not set");
ServerHttpRequest request = exchange.getRequest();
StringBuilder targetUrl = new StringBuilder();
if (isContextRelative() && url.startsWith("/")) {
targetUrl.append(request.getPath().contextPath().value());
}
targetUrl.append(url);
if (StringUtils.hasText(targetUrl)) {
Map<String, String> uriVars = getCurrentUriVariables(exchange);
targetUrl = expandTargetUrlTemplate(targetUrl.toString(), model, uriVars);
}
if (isPropagateQuery()) {
targetUrl = appendCurrentRequestQuery(targetUrl.toString(), request);
}
String result = targetUrl.toString();
RequestDataValueProcessor processor = getRequestDataValueProcessor();
return (processor != null ? processor.processUrl(exchange, result) : result);
}
use of org.springframework.http.server.reactive.ServerHttpRequest in project spring-framework by spring-projects.
the class ConsumesRequestCondition method getMatchingCondition.
/**
* Checks if any of the contained media type expressions match the given
* request 'Content-Type' header and returns an instance that is guaranteed
* to contain matching expressions only. The match is performed via
* {@link MediaType#includes(MediaType)}.
* @param exchange the current exchange
* @return the same instance if the condition contains no expressions;
* or a new condition with matching expressions only;
* or {@code null} if no expressions match.
*/
@Override
public ConsumesRequestCondition getMatchingCondition(ServerWebExchange exchange) {
ServerHttpRequest request = exchange.getRequest();
if (CorsUtils.isPreFlightRequest(request)) {
return EMPTY_CONDITION;
}
if (isEmpty()) {
return this;
}
if (!hasBody(request) && !this.bodyRequired) {
return EMPTY_CONDITION;
}
List<ConsumeMediaTypeExpression> result = getMatchingExpressions(exchange);
return !CollectionUtils.isEmpty(result) ? new ConsumesRequestCondition(result) : null;
}
use of org.springframework.http.server.reactive.ServerHttpRequest in project spring-framework by spring-projects.
the class AbstractHandlerMapping method getHandler.
@Override
public Mono<Object> getHandler(ServerWebExchange exchange) {
return getHandlerInternal(exchange).map(handler -> {
if (logger.isDebugEnabled()) {
logger.debug(exchange.getLogPrefix() + "Mapped to " + handler);
}
ServerHttpRequest request = exchange.getRequest();
if (hasCorsConfigurationSource(handler) || CorsUtils.isPreFlightRequest(request)) {
CorsConfiguration config = (this.corsConfigurationSource != null ? this.corsConfigurationSource.getCorsConfiguration(exchange) : null);
CorsConfiguration handlerConfig = getCorsConfiguration(handler, exchange);
config = (config != null ? config.combine(handlerConfig) : handlerConfig);
if (config != null) {
config.validateAllowCredentials();
}
if (!this.corsProcessor.process(config, exchange) || CorsUtils.isPreFlightRequest(request)) {
return NO_OP_HANDLER;
}
}
return handler;
});
}
use of org.springframework.http.server.reactive.ServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerRequestBuilder method build.
@Override
public ServerRequest build() {
ServerHttpRequest serverHttpRequest = new BuiltServerHttpRequest(this.exchange.getRequest().getId(), this.method, this.uri, this.headers, this.cookies, this.body);
ServerWebExchange exchange = new DelegatingServerWebExchange(serverHttpRequest, this.attributes, this.exchange, this.messageReaders);
return new DefaultServerRequest(exchange, this.messageReaders);
}
use of org.springframework.http.server.reactive.ServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class ForwardedHeadersFilter method filter.
@Override
public HttpHeaders filter(HttpHeaders input, ServerWebExchange exchange) {
ServerHttpRequest request = exchange.getRequest();
HttpHeaders original = input;
HttpHeaders updated = new HttpHeaders();
// copy all headers except Forwarded
original.entrySet().stream().filter(entry -> !entry.getKey().toLowerCase().equalsIgnoreCase(FORWARDED_HEADER)).forEach(entry -> updated.addAll(entry.getKey(), entry.getValue()));
List<Forwarded> forwardeds = parse(original.get(FORWARDED_HEADER));
for (Forwarded f : forwardeds) {
updated.add(FORWARDED_HEADER, f.toString());
}
// TODO: add new forwarded
URI uri = request.getURI();
String host = original.getFirst(HttpHeaders.HOST);
Forwarded forwarded = new Forwarded().put("host", host).put("proto", uri.getScheme());
InetSocketAddress remoteAddress = request.getRemoteAddress();
if (remoteAddress != null) {
String forValue = remoteAddress.getAddress().getHostAddress();
int port = remoteAddress.getPort();
if (port >= 0) {
forValue = forValue + ":" + port;
}
forwarded.put("for", forValue);
}
// TODO: support by?
updated.add(FORWARDED_HEADER, forwarded.toHeaderValue());
return updated;
}
Aggregations