View Javadoc
1   package org.esigate.http;
2   
3   import java.util.Locale;
4   
5   import org.apache.http.Header;
6   import org.apache.http.HeaderIterator;
7   import org.apache.http.HttpEntity;
8   import org.apache.http.HttpResponse;
9   import org.apache.http.ProtocolVersion;
10  import org.apache.http.StatusLine;
11  import org.apache.http.client.methods.CloseableHttpResponse;
12  
13  public final class BasicCloseableHttpResponse implements CloseableHttpResponse {
14      private final HttpResponse httpResponse;
15  
16      public static CloseableHttpResponse adapt(HttpResponse response) {
17          if (response instanceof CloseableHttpResponse) {
18              return (CloseableHttpResponse) response;
19          } else {
20              return new BasicCloseableHttpResponse(response);
21          }
22      }
23  
24      private BasicCloseableHttpResponse(HttpResponse httpResponse) {
25          this.httpResponse = httpResponse;
26      }
27  
28      @Override
29      public void close() {
30          // Nothing to do
31      }
32  
33      @Override
34      public StatusLine getStatusLine() {
35          return httpResponse.getStatusLine();
36      }
37  
38      @Override
39      public void setStatusLine(StatusLine statusline) {
40          httpResponse.setStatusLine(statusline);
41      }
42  
43      @Override
44      public ProtocolVersion getProtocolVersion() {
45          return httpResponse.getProtocolVersion();
46      }
47  
48      @Override
49      public void setStatusLine(ProtocolVersion ver, int code) {
50          httpResponse.setStatusLine(ver, code);
51      }
52  
53      @Override
54      public boolean containsHeader(String name) {
55          return httpResponse.containsHeader(name);
56      }
57  
58      @Override
59      public void setStatusLine(ProtocolVersion ver, int code, String reason) {
60          httpResponse.setStatusLine(ver, code, reason);
61      }
62  
63      @Override
64      public Header[] getHeaders(String name) {
65          return httpResponse.getHeaders(name);
66      }
67  
68      @Override
69      public void setStatusCode(int code) {
70          httpResponse.setStatusCode(code);
71      }
72  
73      @Override
74      public Header getFirstHeader(String name) {
75          return httpResponse.getFirstHeader(name);
76      }
77  
78      @Override
79      public Header getLastHeader(String name) {
80          return httpResponse.getLastHeader(name);
81      }
82  
83      @Override
84      public void setReasonPhrase(String reason) {
85          httpResponse.setReasonPhrase(reason);
86      }
87  
88      @Override
89      public Header[] getAllHeaders() {
90          return httpResponse.getAllHeaders();
91      }
92  
93      @Override
94      public HttpEntity getEntity() {
95          return httpResponse.getEntity();
96      }
97  
98      @Override
99      public void addHeader(Header header) {
100         httpResponse.addHeader(header);
101     }
102 
103     @Override
104     public void addHeader(String name, String value) {
105         httpResponse.addHeader(name, value);
106     }
107 
108     @Override
109     public void setEntity(HttpEntity entity) {
110         httpResponse.setEntity(entity);
111     }
112 
113     @Override
114     public void setHeader(Header header) {
115         httpResponse.setHeader(header);
116     }
117 
118     @Override
119     public void setHeader(String name, String value) {
120         httpResponse.setHeader(name, value);
121     }
122 
123     @Override
124     public Locale getLocale() {
125         return httpResponse.getLocale();
126     }
127 
128     @Override
129     public void setHeaders(Header[] headers) {
130         httpResponse.setHeaders(headers);
131     }
132 
133     @Override
134     public void removeHeader(Header header) {
135         httpResponse.removeHeader(header);
136     }
137 
138     @Override
139     public void setLocale(Locale loc) {
140         httpResponse.setLocale(loc);
141     }
142 
143     @Override
144     public void removeHeaders(String name) {
145         httpResponse.removeHeaders(name);
146     }
147 
148     @Override
149     public HeaderIterator headerIterator() {
150         return httpResponse.headerIterator();
151     }
152 
153     @Override
154     public HeaderIterator headerIterator(String name) {
155         return httpResponse.headerIterator(name);
156     }
157 
158     @SuppressWarnings("deprecation")
159     @Override
160     public org.apache.http.params.HttpParams getParams() {
161         return httpResponse.getParams();
162     }
163 
164     @SuppressWarnings("deprecation")
165     @Override
166     public void setParams(org.apache.http.params.HttpParams params) {
167         httpResponse.setParams(params);
168     }
169 
170     @Override
171     public String toString() {
172         return httpResponse.toString();
173     }
174 
175 }