equal
deleted
inserted
replaced
39 import java.util.Optional; |
39 import java.util.Optional; |
40 import java.net.http.HttpClient; |
40 import java.net.http.HttpClient; |
41 import java.net.http.HttpHeaders; |
41 import java.net.http.HttpHeaders; |
42 import java.net.http.HttpRequest; |
42 import java.net.http.HttpRequest; |
43 import jdk.internal.net.http.common.HttpHeadersImpl; |
43 import jdk.internal.net.http.common.HttpHeadersImpl; |
|
44 import jdk.internal.net.http.common.Utils; |
44 import jdk.internal.net.http.websocket.WebSocketRequest; |
45 import jdk.internal.net.http.websocket.WebSocketRequest; |
45 |
46 |
46 import static jdk.internal.net.http.common.Utils.ALLOWED_HEADERS; |
47 import static jdk.internal.net.http.common.Utils.ALLOWED_HEADERS; |
47 |
48 |
48 class HttpRequestImpl extends HttpRequest implements WebSocketRequest { |
49 class HttpRequestImpl extends HttpRequest implements WebSocketRequest { |
92 /** |
93 /** |
93 * Creates an HttpRequestImpl from the given request. |
94 * Creates an HttpRequestImpl from the given request. |
94 */ |
95 */ |
95 public HttpRequestImpl(HttpRequest request, ProxySelector ps) { |
96 public HttpRequestImpl(HttpRequest request, ProxySelector ps) { |
96 String method = request.method(); |
97 String method = request.method(); |
|
98 if (method != null && !Utils.isValidName(method)) |
|
99 throw new IllegalArgumentException("illegal method \"" |
|
100 + method.replace("\n","\\n") |
|
101 .replace("\r", "\\r") |
|
102 .replace("\t", "\\t") |
|
103 + "\""); |
97 this.method = method == null ? "GET" : method; |
104 this.method = method == null ? "GET" : method; |
98 this.userHeaders = request.headers(); |
105 this.userHeaders = ImmutableHeaders.of(request.headers()); |
99 if (request instanceof HttpRequestImpl) { |
106 if (request instanceof HttpRequestImpl) { |
100 // all cases exception WebSocket should have a new system headers |
107 // all cases exception WebSocket should have a new system headers |
101 this.isWebSocket = ((HttpRequestImpl) request).isWebSocket; |
108 this.isWebSocket = ((HttpRequestImpl) request).isWebSocket; |
102 if (isWebSocket) { |
109 if (isWebSocket) { |
103 this.systemHeaders = ((HttpRequestImpl) request).systemHeaders; |
110 this.systemHeaders = ((HttpRequestImpl) request).systemHeaders; |
143 * The newly created HttpRequestImpl does not copy the system headers. |
150 * The newly created HttpRequestImpl does not copy the system headers. |
144 */ |
151 */ |
145 private HttpRequestImpl(URI uri, |
152 private HttpRequestImpl(URI uri, |
146 String method, |
153 String method, |
147 HttpRequestImpl other) { |
154 HttpRequestImpl other) { |
|
155 assert method == null || Utils.isValidName(method); |
148 this.method = method == null? "GET" : method; |
156 this.method = method == null? "GET" : method; |
149 this.userHeaders = other.userHeaders; |
157 this.userHeaders = other.userHeaders; |
150 this.isWebSocket = other.isWebSocket; |
158 this.isWebSocket = other.isWebSocket; |
151 this.systemHeaders = new HttpHeadersImpl(); |
159 this.systemHeaders = new HttpHeadersImpl(); |
152 this.systemHeaders.setHeader("User-Agent", USER_AGENT); |
160 this.systemHeaders.setHeader("User-Agent", USER_AGENT); |