001/* 002 * Copyright 2002-2020 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.server.reactive; 018 019import java.net.InetSocketAddress; 020import java.net.URI; 021 022import reactor.core.publisher.Flux; 023 024import org.springframework.core.io.buffer.DataBuffer; 025import org.springframework.http.HttpCookie; 026import org.springframework.http.HttpHeaders; 027import org.springframework.http.HttpMethod; 028import org.springframework.http.server.RequestPath; 029import org.springframework.lang.Nullable; 030import org.springframework.util.Assert; 031import org.springframework.util.MultiValueMap; 032 033/** 034 * Wraps another {@link ServerHttpRequest} 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 ServerHttpRequestDecorator implements ServerHttpRequest { 041 042 private final ServerHttpRequest delegate; 043 044 045 public ServerHttpRequestDecorator(ServerHttpRequest delegate) { 046 Assert.notNull(delegate, "Delegate is required"); 047 this.delegate = delegate; 048 } 049 050 051 public ServerHttpRequest getDelegate() { 052 return this.delegate; 053 } 054 055 056 // ServerHttpRequest delegation methods... 057 058 @Override 059 public String getId() { 060 return getDelegate().getId(); 061 } 062 063 @Override 064 @Nullable 065 public HttpMethod getMethod() { 066 return getDelegate().getMethod(); 067 } 068 069 @Override 070 public String getMethodValue() { 071 return getDelegate().getMethodValue(); 072 } 073 074 @Override 075 public URI getURI() { 076 return getDelegate().getURI(); 077 } 078 079 @Override 080 public RequestPath getPath() { 081 return getDelegate().getPath(); 082 } 083 084 @Override 085 public MultiValueMap<String, String> getQueryParams() { 086 return getDelegate().getQueryParams(); 087 } 088 089 @Override 090 public HttpHeaders getHeaders() { 091 return getDelegate().getHeaders(); 092 } 093 094 @Override 095 public MultiValueMap<String, HttpCookie> getCookies() { 096 return getDelegate().getCookies(); 097 } 098 099 @Override 100 @Nullable 101 public InetSocketAddress getLocalAddress() { 102 return getDelegate().getLocalAddress(); 103 } 104 105 @Override 106 @Nullable 107 public InetSocketAddress getRemoteAddress() { 108 return getDelegate().getRemoteAddress(); 109 } 110 111 @Override 112 @Nullable 113 public SslInfo getSslInfo() { 114 return getDelegate().getSslInfo(); 115 } 116 117 @Override 118 public Flux<DataBuffer> getBody() { 119 return getDelegate().getBody(); 120 } 121 122 123 @Override 124 public String toString() { 125 return getClass().getSimpleName() + " [delegate=" + getDelegate() + "]"; 126 } 127 128}