1 /* |
|
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package java.net.http.internal; |
|
27 |
|
28 import java.net.URI; |
|
29 import java.net.http.HttpClient; |
|
30 import java.net.http.HttpHeaders; |
|
31 |
|
32 /** |
|
33 * Response headers and status code. |
|
34 */ |
|
35 class Response { |
|
36 final HttpHeaders headers; |
|
37 final int statusCode; |
|
38 final HttpRequestImpl request; |
|
39 final Exchange<?> exchange; |
|
40 final HttpClient.Version version; |
|
41 final boolean isConnectResponse; |
|
42 |
|
43 Response(HttpRequestImpl req, |
|
44 Exchange<?> exchange, |
|
45 HttpHeaders headers, |
|
46 int statusCode, |
|
47 HttpClient.Version version) { |
|
48 this(req, exchange, headers, statusCode, version, |
|
49 "CONNECT".equalsIgnoreCase(req.method())); |
|
50 } |
|
51 |
|
52 Response(HttpRequestImpl req, |
|
53 Exchange<?> exchange, |
|
54 HttpHeaders headers, |
|
55 int statusCode, |
|
56 HttpClient.Version version, |
|
57 boolean isConnectResponse) { |
|
58 this.headers = headers; |
|
59 this.request = req; |
|
60 this.version = version; |
|
61 this.exchange = exchange; |
|
62 this.statusCode = statusCode; |
|
63 this.isConnectResponse = isConnectResponse; |
|
64 } |
|
65 |
|
66 HttpRequestImpl request() { |
|
67 return request; |
|
68 } |
|
69 |
|
70 HttpClient.Version version() { |
|
71 return version; |
|
72 } |
|
73 |
|
74 HttpHeaders headers() { |
|
75 return headers; |
|
76 } |
|
77 |
|
78 // Exchange<?> exchange() { |
|
79 // return exchange; |
|
80 // } |
|
81 |
|
82 int statusCode() { |
|
83 return statusCode; |
|
84 } |
|
85 |
|
86 @Override |
|
87 public String toString() { |
|
88 StringBuilder sb = new StringBuilder(); |
|
89 String method = request().method(); |
|
90 URI uri = request().uri(); |
|
91 String uristring = uri == null ? "" : uri.toString(); |
|
92 sb.append('(') |
|
93 .append(method) |
|
94 .append(" ") |
|
95 .append(uristring) |
|
96 .append(") ") |
|
97 .append(statusCode()); |
|
98 return sb.toString(); |
|
99 } |
|
100 } |
|