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 reactor.core.publisher.Flux;
020
021import org.springframework.core.io.buffer.DataBuffer;
022import org.springframework.http.HttpHeaders;
023import org.springframework.http.HttpStatus;
024import org.springframework.http.ResponseCookie;
025import org.springframework.util.Assert;
026import org.springframework.util.MultiValueMap;
027
028/**
029 * Wraps another {@link ClientHttpResponse} and delegates all methods to it.
030 * Sub-classes can override specific methods selectively.
031 *
032 * @author Rossen Stoyanchev
033 * @since 5.0
034 */
035public class ClientHttpResponseDecorator implements ClientHttpResponse {
036
037        private final ClientHttpResponse delegate;
038
039
040        public ClientHttpResponseDecorator(ClientHttpResponse delegate) {
041                Assert.notNull(delegate, "Delegate is required");
042                this.delegate = delegate;
043        }
044
045
046        public ClientHttpResponse getDelegate() {
047                return this.delegate;
048        }
049
050
051        // ClientHttpResponse delegation methods...
052
053        @Override
054        public HttpStatus getStatusCode() {
055                return this.delegate.getStatusCode();
056        }
057
058        @Override
059        public int getRawStatusCode() {
060                return this.delegate.getRawStatusCode();
061        }
062
063        @Override
064        public HttpHeaders getHeaders() {
065                return this.delegate.getHeaders();
066        }
067
068        @Override
069        public MultiValueMap<String, ResponseCookie> getCookies() {
070                return this.delegate.getCookies();
071        }
072
073        @Override
074        public Flux<DataBuffer> getBody() {
075                return this.delegate.getBody();
076        }
077
078        @Override
079        public String toString() {
080                return getClass().getSimpleName() + " [delegate=" + getDelegate() + "]";
081        }
082
083}