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/ImmutableHttpRequest.java
41171 views
1
/*
2
* Copyright (c) 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.net.http.HttpHeaders;
30
import java.net.http.HttpRequest;
31
import java.time.Duration;
32
import java.util.Objects;
33
import java.util.Optional;
34
import java.net.http.HttpClient.Version;
35
import static jdk.internal.net.http.common.Utils.ALLOWED_HEADERS;
36
37
final class ImmutableHttpRequest extends HttpRequest {
38
39
private final String method;
40
private final URI uri;
41
private final HttpHeaders headers;
42
private final Optional<BodyPublisher> requestPublisher;
43
private final boolean expectContinue;
44
private final Optional<Duration> timeout;
45
private final Optional<Version> version;
46
47
/** Creates an ImmutableHttpRequest from the given builder. */
48
ImmutableHttpRequest(HttpRequestBuilderImpl builder) {
49
this.method = Objects.requireNonNull(builder.method());
50
this.uri = Objects.requireNonNull(builder.uri());
51
this.headers = HttpHeaders.of(builder.headersBuilder().map(), ALLOWED_HEADERS);
52
this.requestPublisher = Optional.ofNullable(builder.bodyPublisher());
53
this.expectContinue = builder.expectContinue();
54
this.timeout = Optional.ofNullable(builder.timeout());
55
this.version = Objects.requireNonNull(builder.version());
56
}
57
58
@Override
59
public String method() { return method; }
60
61
@Override
62
public URI uri() { return uri; }
63
64
@Override
65
public HttpHeaders headers() {
66
return headers;
67
}
68
69
@Override
70
public Optional<BodyPublisher> bodyPublisher() { return requestPublisher; }
71
72
@Override
73
public boolean expectContinue() { return expectContinue; }
74
75
@Override
76
public Optional<Duration> timeout() { return timeout; }
77
78
@Override
79
public Optional<Version> version() { return version; }
80
81
@Override
82
public String toString() {
83
return uri.toString() + " " + method;
84
}
85
}
86
87