75 ** |
75 ** |
76 * @param <T> the response body type |
76 * @param <T> the response body type |
77 * |
77 * |
78 * @since 11 |
78 * @since 11 |
79 */ |
79 */ |
80 public abstract class HttpResponse<T> { |
80 public interface HttpResponse<T> { |
81 |
81 |
82 /** |
|
83 * Creates an HttpResponse. |
|
84 */ |
|
85 protected HttpResponse() { } |
|
86 |
82 |
87 /** |
83 /** |
88 * Returns the status code for this response. |
84 * Returns the status code for this response. |
89 * |
85 * |
90 * @return the response code |
86 * @return the response code |
91 */ |
87 */ |
92 public abstract int statusCode(); |
88 public int statusCode(); |
93 |
89 |
94 /** |
90 /** |
95 * Returns the {@link HttpRequest} corresponding to this response. |
91 * Returns the {@link HttpRequest} corresponding to this response. |
96 * |
92 * |
97 * <p> This may not be the original request provided by the caller, |
93 * <p> This may not be the original request provided by the caller, |
99 * |
95 * |
100 * @see #previousResponse() |
96 * @see #previousResponse() |
101 * |
97 * |
102 * @return the request |
98 * @return the request |
103 */ |
99 */ |
104 public abstract HttpRequest request(); |
100 public HttpRequest request(); |
105 |
101 |
106 /** |
102 /** |
107 * Returns an {@code Optional} containing the previous intermediate response |
103 * Returns an {@code Optional} containing the previous intermediate response |
108 * if one was received. An intermediate response is one that is received |
104 * if one was received. An intermediate response is one that is received |
109 * as a result of redirection or authentication. If no previous response |
105 * as a result of redirection or authentication. If no previous response |
110 * was received then an empty {@code Optional} is returned. |
106 * was received then an empty {@code Optional} is returned. |
111 * |
107 * |
112 * @return an Optional containing the HttpResponse, if any. |
108 * @return an Optional containing the HttpResponse, if any. |
113 */ |
109 */ |
114 public abstract Optional<HttpResponse<T>> previousResponse(); |
110 public Optional<HttpResponse<T>> previousResponse(); |
115 |
111 |
116 /** |
112 /** |
117 * Returns the received response headers. |
113 * Returns the received response headers. |
118 * |
114 * |
119 * @return the response headers |
115 * @return the response headers |
120 */ |
116 */ |
121 public abstract HttpHeaders headers(); |
117 public HttpHeaders headers(); |
122 |
118 |
123 /** |
119 /** |
124 * Returns the body. Depending on the type of {@code T}, the returned body |
120 * Returns the body. Depending on the type of {@code T}, the returned body |
125 * may represent the body after it was read (such as {@code byte[]}, or |
121 * may represent the body after it was read (such as {@code byte[]}, or |
126 * {@code String}, or {@code Path}) or it may represent an object with |
122 * {@code String}, or {@code Path}) or it may represent an object with |
129 * <p> If this {@code HttpResponse} was returned from an invocation of |
125 * <p> If this {@code HttpResponse} was returned from an invocation of |
130 * {@link #previousResponse()} then this method returns {@code null} |
126 * {@link #previousResponse()} then this method returns {@code null} |
131 * |
127 * |
132 * @return the body |
128 * @return the body |
133 */ |
129 */ |
134 public abstract T body(); |
130 public T body(); |
135 |
131 |
136 /** |
132 /** |
137 * Returns an {@link Optional} containing the {@link SSLSession} in effect |
133 * Returns an {@link Optional} containing the {@link SSLSession} in effect |
138 * for this response. Returns an empty {@code Optional} if this is not a |
134 * for this response. Returns an empty {@code Optional} if this is not a |
139 * <i>HTTPS</i> response. |
135 * <i>HTTPS</i> response. |
140 * |
136 * |
141 * @return an {@code Optional} containing the {@code SSLSession} associated |
137 * @return an {@code Optional} containing the {@code SSLSession} associated |
142 * with the response |
138 * with the response |
143 */ |
139 */ |
144 public abstract Optional<SSLSession> sslSession(); |
140 public Optional<SSLSession> sslSession(); |
145 |
141 |
146 /** |
142 /** |
147 * Returns the {@code URI} that the response was received from. This may be |
143 * Returns the {@code URI} that the response was received from. This may be |
148 * different from the request {@code URI} if redirection occurred. |
144 * different from the request {@code URI} if redirection occurred. |
149 * |
145 * |
150 * @return the URI of the response |
146 * @return the URI of the response |
151 */ |
147 */ |
152 public abstract URI uri(); |
148 public URI uri(); |
153 |
149 |
154 /** |
150 /** |
155 * Returns the HTTP protocol version that was used for this response. |
151 * Returns the HTTP protocol version that was used for this response. |
156 * |
152 * |
157 * @return HTTP protocol version |
153 * @return HTTP protocol version |
158 */ |
154 */ |
159 public abstract HttpClient.Version version(); |
155 public HttpClient.Version version(); |
160 |
156 |
161 |
157 |
162 private static String pathForSecurityCheck(Path path) { |
158 private static String pathForSecurityCheck(Path path) { |
163 return path.toFile().getPath(); |
159 return path.toFile().getPath(); |
164 } |
160 } |