Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.net.http/share/classes/jdk/internal/net/http/Response.java
41171 views
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 jdk.internal.net.http;
27
28
import java.net.URI;
29
import java.io.IOException;
30
import java.net.http.HttpClient;
31
import java.net.http.HttpHeaders;
32
import java.net.InetSocketAddress;
33
import javax.net.ssl.SSLEngine;
34
import javax.net.ssl.SSLSession;
35
import jdk.internal.net.http.common.Utils;
36
37
/**
38
* Response headers and status code.
39
*/
40
class Response {
41
final HttpHeaders headers;
42
final int statusCode;
43
final HttpRequestImpl request;
44
final Exchange<?> exchange;
45
final HttpClient.Version version;
46
final boolean isConnectResponse;
47
final SSLSession sslSession;
48
final InetSocketAddress localAddress;
49
50
Response(HttpRequestImpl req,
51
Exchange<?> exchange,
52
HttpHeaders headers,
53
HttpConnection connection,
54
int statusCode,
55
HttpClient.Version version) {
56
this(req, exchange, headers, connection, statusCode, version,
57
"CONNECT".equalsIgnoreCase(req.method()));
58
}
59
60
Response(HttpRequestImpl req,
61
Exchange<?> exchange,
62
HttpHeaders headers,
63
HttpConnection connection,
64
int statusCode,
65
HttpClient.Version version,
66
boolean isConnectResponse) {
67
this.headers = headers;
68
this.request = req;
69
this.version = version;
70
this.exchange = exchange;
71
this.statusCode = statusCode;
72
this.isConnectResponse = isConnectResponse;
73
if (connection != null) {
74
InetSocketAddress a;
75
try {
76
a = (InetSocketAddress)connection.channel().getLocalAddress();
77
} catch (IOException e) {
78
a = null;
79
}
80
this.localAddress = a;
81
if (connection instanceof AbstractAsyncSSLConnection) {
82
AbstractAsyncSSLConnection cc = (AbstractAsyncSSLConnection)connection;
83
SSLEngine engine = cc.getEngine();
84
sslSession = Utils.immutableSession(engine.getSession());
85
} else {
86
sslSession = null;
87
}
88
} else {
89
sslSession = null;
90
localAddress = null;
91
}
92
}
93
94
HttpRequestImpl request() {
95
return request;
96
}
97
98
HttpClient.Version version() {
99
return version;
100
}
101
102
HttpHeaders headers() {
103
return headers;
104
}
105
106
int statusCode() {
107
return statusCode;
108
}
109
110
SSLSession getSSLSession() {
111
return sslSession;
112
}
113
114
@Override
115
public String toString() {
116
StringBuilder sb = new StringBuilder();
117
String method = request().method();
118
URI uri = request().uri();
119
String uristring = uri == null ? "" : uri.toString();
120
sb.append('(')
121
.append(method)
122
.append(" ")
123
.append(uristring)
124
.append(") ")
125
.append(statusCode());
126
sb.append(" ").append(version);
127
if (localAddress != null)
128
sb.append(" Local port: ").append(localAddress.getPort());
129
return sb.toString();
130
}
131
}
132
133