< prev index next >
src/java.httpclient/share/classes/java/net/http/HttpResponseImpl.java
Print this page
*** 24,33 ****
--- 24,34 ----
*/
package java.net.http;
import java.io.IOException;
+ import java.io.UncheckedIOException;
import java.net.URI;
import java.nio.ByteBuffer;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.util.concurrent.CompletableFuture;
*** 40,70 ****
class HttpResponseImpl extends HttpResponse {
int responseCode;
Exchange exchange;
HttpRequestImpl request;
! HttpHeaders1 headers;
! HttpHeaders1 trailers;
SSLParameters sslParameters;
URI uri;
HttpClient.Version version;
AccessControlContext acc;
RawChannel rawchan;
HttpConnection connection;
! public HttpResponseImpl(int responseCode, Exchange exch, HttpHeaders1 headers,
! HttpHeaders1 trailers, SSLParameters sslParameters,
HttpClient.Version version, HttpConnection connection) {
this.responseCode = responseCode;
this.exchange = exch;
this.request = exchange.request();
this.headers = headers;
this.trailers = trailers;
this.sslParameters = sslParameters;
this.uri = request.uri();
this.version = version;
this.connection = connection;
}
@Override
public int statusCode() {
return responseCode;
--- 41,89 ----
class HttpResponseImpl extends HttpResponse {
int responseCode;
Exchange exchange;
HttpRequestImpl request;
! HttpHeaders headers;
! HttpHeaders trailers;
SSLParameters sslParameters;
URI uri;
HttpClient.Version version;
AccessControlContext acc;
RawChannel rawchan;
HttpConnection connection;
+ final Stream stream;
! public HttpResponseImpl(int responseCode, Exchange exch, HttpHeaders headers,
! HttpHeaders trailers, SSLParameters sslParameters,
HttpClient.Version version, HttpConnection connection) {
this.responseCode = responseCode;
this.exchange = exch;
this.request = exchange.request();
this.headers = headers;
this.trailers = trailers;
this.sslParameters = sslParameters;
this.uri = request.uri();
this.version = version;
this.connection = connection;
+ this.stream = null;
+ }
+
+ // A response to a PUSH_PROMISE
+ public HttpResponseImpl(int responseCode, HttpRequestImpl pushRequest,
+ ImmutableHeaders headers,
+ Stream stream, SSLParameters sslParameters) {
+ this.responseCode = responseCode;
+ this.exchange = null;
+ this.request = pushRequest;
+ this.headers = headers;
+ this.trailers = null;
+ this.sslParameters = sslParameters;
+ this.uri = request.uri(); // TODO: take from headers
+ this.version = HttpClient.Version.HTTP_2;
+ this.connection = null;
+ this.stream = stream;
}
@Override
public int statusCode() {
return responseCode;
*** 75,104 ****
return request;
}
@Override
public HttpHeaders headers() {
- headers.makeUnmodifiable();
return headers;
}
@Override
public HttpHeaders trailers() {
- trailers.makeUnmodifiable();
return trailers;
}
@Override
public <T> T body(java.net.http.HttpResponse.BodyProcessor<T> processor) {
return exchange.responseBody(processor);
}
@Override
public <T> CompletableFuture<T> bodyAsync(java.net.http.HttpResponse.BodyProcessor<T> processor) {
acc = AccessController.getContext();
return exchange.responseBodyAsync(processor);
}
@Override
public SSLParameters sslParameters() {
return sslParameters;
--- 94,132 ----
return request;
}
@Override
public HttpHeaders headers() {
return headers;
}
@Override
public HttpHeaders trailers() {
return trailers;
}
@Override
public <T> T body(java.net.http.HttpResponse.BodyProcessor<T> processor) {
+ try {
+ if (exchange != null) {
return exchange.responseBody(processor);
+ } else {
+ return stream.responseBody(processor);
+ }
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
}
@Override
public <T> CompletableFuture<T> bodyAsync(java.net.http.HttpResponse.BodyProcessor<T> processor) {
acc = AccessController.getContext();
+ if (exchange != null)
return exchange.responseBodyAsync(processor);
+ else
+ return stream.responseBodyAsync(processor);
}
@Override
public SSLParameters sslParameters() {
return sslParameters;
< prev index next >