Skip to content

Commit

Permalink
Merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
corretto-github-robot committed Sep 24, 2024
2 parents 132bd03 + 0358cbd commit c988026
Show file tree
Hide file tree
Showing 5 changed files with 420 additions and 42 deletions.
107 changes: 68 additions & 39 deletions src/java.net.http/share/classes/jdk/internal/net/http/Stream.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -136,6 +136,7 @@ class Stream<T> extends ExchangeImpl<T> {
private volatile boolean remotelyClosed;
private volatile boolean closed;
private volatile boolean endStreamSent;
private volatile boolean finalResponseCodeReceived;
// Indicates the first reason that was invoked when sending a ResetFrame
// to the server. A streamState of 0 indicates that no reset was sent.
// (see markStream(int code)
Expand Down Expand Up @@ -474,30 +475,44 @@ DecodingCallback rspHeadersConsumer() {

protected void handleResponse() throws IOException {
HttpHeaders responseHeaders = responseHeadersBuilder.build();
responseCode = (int)responseHeaders
.firstValueAsLong(":status")
.orElseThrow(() -> new IOException("no statuscode in response"));

response = new Response(
request, exchange, responseHeaders, connection(),
responseCode, HttpClient.Version.HTTP_2);
if (!finalResponseCodeReceived) {
responseCode = (int) responseHeaders
.firstValueAsLong(":status")
.orElseThrow(() -> new IOException("no statuscode in response"));
// If informational code, response is partially complete
if (responseCode < 100 || responseCode > 199)
this.finalResponseCodeReceived = true;

response = new Response(
request, exchange, responseHeaders, connection(),
responseCode, HttpClient.Version.HTTP_2);

/* TODO: review if needs to be removed
the value is not used, but in case `content-length` doesn't parse as
long, there will be NumberFormatException. If left as is, make sure
code up the stack handles NFE correctly. */
responseHeaders.firstValueAsLong("content-length");
responseHeaders.firstValueAsLong("content-length");

if (Log.headers()) {
StringBuilder sb = new StringBuilder("RESPONSE HEADERS:\n");
Log.dumpHeaders(sb, " ", responseHeaders);
Log.logHeaders(sb.toString());
}
if (Log.headers()) {
StringBuilder sb = new StringBuilder("RESPONSE HEADERS:\n");
Log.dumpHeaders(sb, " ", responseHeaders);
Log.logHeaders(sb.toString());
}

// this will clear the response headers
rspHeadersConsumer.reset();

// this will clear the response headers
rspHeadersConsumer.reset();
completeResponse(response);
} else {
if (Log.headers()) {
StringBuilder sb = new StringBuilder("TRAILING HEADERS:\n");
Log.dumpHeaders(sb, " ", responseHeaders);
Log.logHeaders(sb.toString());
}
rspHeadersConsumer.reset();
}

completeResponse(response);
}

void incoming_reset(ResetFrame frame) {
Expand Down Expand Up @@ -1313,6 +1328,7 @@ static class PushedStream<T> extends Stream<T> {
CompletableFuture<HttpResponse<T>> responseCF;
final HttpRequestImpl pushReq;
HttpResponse.BodyHandler<T> pushHandler;
private volatile boolean finalPushResponseCodeReceived;

PushedStream(PushGroup<T> pushGroup,
Http2Connection connection,
Expand Down Expand Up @@ -1409,35 +1425,48 @@ void completeResponseExceptionally(Throwable t) {
@Override
protected void handleResponse() {
HttpHeaders responseHeaders = responseHeadersBuilder.build();
responseCode = (int)responseHeaders
.firstValueAsLong(":status")
.orElse(-1);

if (responseCode == -1) {
completeResponseExceptionally(new IOException("No status code"));
}
if (!finalPushResponseCodeReceived) {
responseCode = (int)responseHeaders
.firstValueAsLong(":status")
.orElse(-1);

this.response = new Response(
pushReq, exchange, responseHeaders, connection(),
responseCode, HttpClient.Version.HTTP_2);
if (responseCode == -1) {
completeResponseExceptionally(new IOException("No status code"));
}

/* TODO: review if needs to be removed
the value is not used, but in case `content-length` doesn't parse
as long, there will be NumberFormatException. If left as is, make
sure code up the stack handles NFE correctly. */
responseHeaders.firstValueAsLong("content-length");
this.finalPushResponseCodeReceived = true;

if (Log.headers()) {
StringBuilder sb = new StringBuilder("RESPONSE HEADERS");
sb.append(" (streamid=").append(streamid).append("):\n");
Log.dumpHeaders(sb, " ", responseHeaders);
Log.logHeaders(sb.toString());
}
this.response = new Response(
pushReq, exchange, responseHeaders, connection(),
responseCode, HttpClient.Version.HTTP_2);

rspHeadersConsumer.reset();
/* TODO: review if needs to be removed
the value is not used, but in case `content-length` doesn't parse
as long, there will be NumberFormatException. If left as is, make
sure code up the stack handles NFE correctly. */
responseHeaders.firstValueAsLong("content-length");

// different implementations for normal streams and pushed streams
completeResponse(response);
if (Log.headers()) {
StringBuilder sb = new StringBuilder("RESPONSE HEADERS");
sb.append(" (streamid=").append(streamid).append("):\n");
Log.dumpHeaders(sb, " ", responseHeaders);
Log.logHeaders(sb.toString());
}

rspHeadersConsumer.reset();

// different implementations for normal streams and pushed streams
completeResponse(response);
} else {
if (Log.headers()) {
StringBuilder sb = new StringBuilder("TRAILING HEADERS");
sb.append(" (streamid=").append(streamid).append("):\n");
Log.dumpHeaders(sb, " ", responseHeaders);
Log.logHeaders(sb.toString());
}
rspHeadersConsumer.reset();
}
}
}

Expand Down
Loading

0 comments on commit c988026

Please sign in to comment.