8000 Send the response headers HttpServerUtil is given by lorexoff · Pull Request #52363 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Send the response headers HttpServerUtil is given - #52363

Merged
ahus1 merged 3 commits into
keycloak:mainfrom
lorexoff:fix-httpserverutil-headers
Oct 3, 2026
Merged

ahus1 merged 3 commits into
keycloak:mainfrom
lorexoff:fix-httpserverutil-headers

Conversation

@lorexoff
@lorexoff lorexoff commented Sep 3, 2026
Copy link
Copy Markdown
Contributor

Closes #52362

HttpServerUtil.sendResponse added the caller's headers to exchange.getResponseHeaders() after calling exchange.sendResponseHeaders(...), which has already transmitted the header block — so they never reached the client. This moves the two-line block above that call.

The only current caller, TrustMaterialIdentityProviderTest, passes a Content-Type and does not assert on it, which is why the helper has been usable in spite of this.

Verified with a handler written exactly as the helper writes it, read back with java.net.http.HttpClient:

/after  (headers set after sendResponseHeaders)  -> x-amzn-ErrorType = <ABSENT>
/before (headers set before sendResponseHeaders) -> x-amzn-ErrorType = MessageRejected

Found while writing an integration test whose stub endpoint has to return a vendor-specific error header (#52361); that PR carries its own small helper so the two are independent.

Disclosure per CONTRIBUTING: AI agents were used in researching and writing this change.

Copilot AI balanced review requested due to automatic review settings September 3, 2026 10:56
@lorexoff
lorexoff requested a review from a team as a code owner September 3, 2026 10:56
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The corrected header behavior needs an automated regression test.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes HttpServerUtil.sendResponse so caller-provided headers reach clients.

Changes:

  • Applies response headers before sending the HTTP header block.
  • Documents the required ordering.
File summaries
File Description
test-framework/core/src/main/java/org/keycloak/testframework/util/HttpServerUtil.java Corrects response-header sequencing.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

sendResponseHeaders transmits the header block, so the headers the caller passed
were being added to the response after it had already gone out and never reached
the client. The only current caller does not assert on them, which is why this
went unnoticed.

Closes keycloak#52362

Signed-off-by: lorexoff <rocca.lorenzo04@gmail.com>
Copilot AI review requested due to automatic review settings September 3, 2026 11:43
@lorexoff
lorexoff force-pushed the fix-httpserverutil-headers branch from 5e8190c to a8ea7ae Compare September 3, 2026 11:43
@lorexoff
lorexoff commented Sep 3, 2026
Copy link
Copy Markdown
Contributor Author

Fair point — a behaviour fix with no assertion is one refactor away from coming back. Added HttpServerUtilTest, which serves a response through HttpServerUtil.sendResponse from a real HttpServer and reads it back with a real HttpClient.

Verified it actually bites: with the two lines moved back below sendResponseHeaders, it fails with

Expected: is "value"
     but: was null

and passes with the fix in place. There is a second case for the no-headers, no-body response, so the null-argument path stays covered too.

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The ordering fix is correct, focused, and covered by an appropriate regression test.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings September 11, 2026 07:27
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is focused and covered by regression tests.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@ahus1 ahus1 self-assigned this Sep 23, 2026
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
Copilot AI balanced review requested due to automatic review settings October 3, 2026 12:34
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused fix follows the HTTP server API contract and is covered by direct client-server tests.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

@ahus1
ahus1 enabled auto-merge (squash) October 3, 2026 12:36
@ahus1
ahus1 disabled auto-merge October 3, 2026 12:36
@ahus1
ahus1 enabled auto-merge (squash) October 3, 2026 12:37
@ahus1 ahus1 left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this fix!

@ahus1
ahus1 merged commit 9b7c2d4 into keycloak:main Oct 3, 2026
97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpServerUtil.sendResponse drops the headers it is given

3 participants

0