All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.web.reactive.function.server.support.ServerRequestWrapper Maven / Gradle / Ivy

/*
 * Copyright 2002-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.web.reactive.function.server.support;

import java.net.InetSocketAddress;
import java.net.URI;
import java.nio.charset.Charset;
import java.security.Principal;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalLong;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRange;
import org.springframework.http.MediaType;
import org.springframework.http.codec.HttpMessageReader;
import org.springframework.http.codec.multipart.Part;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebSession;
import org.springframework.web.util.UriBuilder;

/**
 * Implementation of the {@link ServerRequest} interface that can be subclassed
 * to adapt the request in a
 * {@link org.springframework.web.reactive.function.server.HandlerFilterFunction handler filter function}.
 * All methods default to calling through to the wrapped request.
 *
 * @author Arjen Poutsma
 * @since 5.0
 */
public class ServerRequestWrapper implements ServerRequest {

	private final ServerRequest delegate;


	/**
	 * Create a new {@code ServerRequestWrapper} that wraps the given request.
	 * @param delegate the request to wrap
	 */
	public ServerRequestWrapper(ServerRequest delegate) {
		Assert.notNull(delegate, "Delegate must not be null");
		this.delegate = delegate;
	}


	/**
	 * Return the wrapped request.
	 */
	public ServerRequest request() {
		return this.delegate;
	}

	@Override
	public HttpMethod method() {
		return this.delegate.method();
	}

	@Override
	public String methodName() {
		return this.delegate.methodName();
	}

	@Override
	public URI uri() {
		return this.delegate.uri();
	}

	@Override
	public UriBuilder uriBuilder() {
		return this.delegate.uriBuilder();
	}

	@Override
	public String path() {
		return this.delegate.path();
	}

	@Override
	public PathContainer pathContainer() {
		return this.delegate.pathContainer();
	}

	@Override
	public Headers headers() {
		return this.delegate.headers();
	}

	@Override
	public MultiValueMap cookies() {
		return this.delegate.cookies();
	}

	@Override
	public Optional remoteAddress() {
		return this.delegate.remoteAddress();
	}

	@Override
	public List> messageReaders() {
		return this.delegate.messageReaders();
	}

	@Override
	public  T body(BodyExtractor extractor) {
		return this.delegate.body(extractor);
	}

	@Override
	public  T body(BodyExtractor extractor, Map hints) {
		return this.delegate.body(extractor, hints);
	}

	@Override
	public  Mono bodyToMono(Class elementClass) {
		return this.delegate.bodyToMono(elementClass);
	}

	@Override
	public  Mono bodyToMono(ParameterizedTypeReference typeReference) {
		return this.delegate.bodyToMono(typeReference);
	}

	@Override
	public  Flux bodyToFlux(Class elementClass) {
		return this.delegate.bodyToFlux(elementClass);
	}

	@Override
	public  Flux bodyToFlux(ParameterizedTypeReference typeReference) {
		return this.delegate.bodyToFlux(typeReference);
	}

	@Override
	public Optional attribute(String name) {
		return this.delegate.attribute(name);
	}

	@Override
	public Map attributes() {
		return this.delegate.attributes();
	}

	@Override
	public Optional queryParam(String name) {
		return this.delegate.queryParam(name);
	}

	@Override
	public MultiValueMap queryParams() {
		return this.delegate.queryParams();
	}

	@Override
	public String pathVariable(String name) {
		return this.delegate.pathVariable(name);
	}

	@Override
	public Map pathVariables() {
		return this.delegate.pathVariables();
	}

	@Override
	public Mono session() {
		return this.delegate.session();
	}

	@Override
	public Mono principal() {
		return this.delegate.principal();
	}

	@Override
	public Mono> formData() {
		return this.delegate.formData();
	}

	@Override
	public Mono> multipartData() {
		return this.delegate.multipartData();
	}

	@Override
	public ServerWebExchange exchange() {
		return this.delegate.exchange();
	}

	/**
	 * Implementation of the {@code Headers} interface that can be subclassed
	 * to adapt the headers in a
	 * {@link org.springframework.web.reactive.function.server.HandlerFilterFunction handler filter function}.
	 * All methods default to calling through to the wrapped headers.
	 */
	public static class HeadersWrapper implements ServerRequest.Headers {

		private final Headers headers;

		/**
		 * Create a new {@code HeadersWrapper} that wraps the given request.
		 * @param headers the headers to wrap
		 */
		public HeadersWrapper(Headers headers) {
			Assert.notNull(headers, "Headers must not be null");
			this.headers = headers;
		}

		@Override
		public List accept() {
			return this.headers.accept();
		}

		@Override
		public List acceptCharset() {
			return this.headers.acceptCharset();
		}

		@Override
		public List acceptLanguage() {
			return this.headers.acceptLanguage();
		}

		@Override
		public OptionalLong contentLength() {
			return this.headers.contentLength();
		}

		@Override
		public Optional contentType() {
			return this.headers.contentType();
		}

		@Override
		public InetSocketAddress host() {
			return this.headers.host();
		}

		@Override
		public List range() {
			return this.headers.range();
		}

		@Override
		public List header(String headerName) {
			return this.headers.header(headerName);
		}

		@Override
		public HttpHeaders asHttpHeaders() {
			return this.headers.asHttpHeaders();
		}
	}

}