001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.http.client.reactive;
018
019import java.net.URI;
020import java.util.function.Supplier;
021
022import org.reactivestreams.Publisher;
023import reactor.core.publisher.Mono;
024
025import org.springframework.core.io.buffer.DataBuffer;
026import org.springframework.core.io.buffer.DataBufferFactory;
027import org.springframework.http.HttpCookie;
028import org.springframework.http.HttpHeaders;
029import org.springframework.http.HttpMethod;
030import org.springframework.util.Assert;
031import org.springframework.util.MultiValueMap;
032
033/**
034 * Wraps another {@link ClientHttpRequest} and delegates all methods to it.
035 * Sub-classes can override specific methods selectively.
036 *
037 * @author Rossen Stoyanchev
038 * @since 5.0
039 */
040public class ClientHttpRequestDecorator implements ClientHttpRequest {
041
042        private final ClientHttpRequest delegate;
043
044
045        public ClientHttpRequestDecorator(ClientHttpRequest delegate) {
046                Assert.notNull(delegate, "Delegate is required");
047                this.delegate = delegate;
048        }
049
050
051        public ClientHttpRequest getDelegate() {
052                return this.delegate;
053        }
054
055
056        // ClientHttpRequest delegation methods...
057
058        @Override
059        public HttpMethod getMethod() {
060                return this.delegate.getMethod();
061        }
062
063        @Override
064        public URI getURI() {
065                return this.delegate.getURI();
066        }
067
068        @Override
069        public HttpHeaders getHeaders() {
070                return this.delegate.getHeaders();
071        }
072
073        @Override
074        public MultiValueMap<String, HttpCookie> getCookies() {
075                return this.delegate.getCookies();
076        }
077
078        @Override
079        public DataBufferFactory bufferFactory() {
080                return this.delegate.bufferFactory();
081        }
082
083        @Override
084        public void beforeCommit(Supplier<? extends Mono<Void>> action) {
085                this.delegate.beforeCommit(action);
086        }
087
088        @Override
089        public boolean isCommitted() {
090                return this.delegate.isCommitted();
091        }
092
093        @Override
094        public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) {
095                return this.delegate.writeWith(body);
096        }
097
098        @Override
099        public Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) {
100                return this.delegate.writeAndFlushWith(body);
101        }
102
103        @Override
104        public Mono<Void> setComplete() {
105                return this.delegate.setComplete();
106        }
107
108
109        @Override
110        public String toString() {
111                return getClass().getSimpleName() + " [delegate=" + getDelegate() + "]";
112        }
113
114}