Skip to content

Conversation

@ehs208
Copy link
Contributor

@ehs208 ehs208 commented Nov 11, 2025

Summary

This patch addresses the issue where HttpResponse.body() returns null for 407 responses when using HTTPS through a proxy, while HTTP requests correctly return the response body.

Problem

When an HTTPS request receives a 407 Proxy Authentication Required response, the response body is discarded during CONNECT tunnel establishment. This is inconsistent with HTTP behavior where the body is properly returned.

Root cause:

  • HTTPS uses MultiExchange<Void> for CONNECT requests
  • The body is explicitly ignored via ignoreBody() on 407 responses
  • No mechanism exists to preserve the body for later retrieval

Proposed Solution

I propose the following changes to preserve and return the 407 response body:

  1. PlainTunnelingConnection.java: Change MultiExchange<Void> to MultiExchange<byte[]> and read the body on 407 responses instead of ignoring it

  2. ProxyAuthenticationRequired.java: Add proxyResponseBody field to carry the body bytes through the exception

  3. Exchange.java: Cache both the proxy response and body, then return them when the application calls body()

Testing

Added comprehensive test (ProxyAuthHttpTest.java) covering:

  • Basic HTTP and HTTPS 407 responses
  • Multiple BodyHandler types: ofString(), ofByteArray(), ofInputStream(), ofLines()
  • Response headers validation

Test results: 38/38 passed

Notes

  • This change only affects 407 responses; all other flows remain unchanged
  • The cached body is cleared after first use to prevent reuse
  • No changes to public APIs; internal implementation only

I'd appreciate any feedback on this approach. If there's a better way to handle this, I'm happy to revise.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8328894: HttpResponse.body() returns null with https target and failed proxy authentication (Bug - P3)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28232/head:pull/28232
$ git checkout pull/28232

Update a local copy of the PR:
$ git checkout pull/28232
$ git pull https://git.openjdk.org/jdk.git pull/28232/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28232

View PR using the GUI difftool:
$ git pr show -t 28232

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28232.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 11, 2025

👋 Welcome back ehs208! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Nov 11, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the net net-dev@openjdk.org label Nov 11, 2025
@openjdk
Copy link

openjdk bot commented Nov 11, 2025

@ehs208 The following label will be automatically applied to this pull request:

  • net

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 11, 2025
@ehs208 ehs208 changed the title 8357554: HttpResponse.body() returns null with https target and failed proxy authentication 8328894: HttpResponse.body() returns null with https target and failed proxy authentication Nov 11, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 11, 2025

Webrevs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

net net-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

1 participant