Skip to content

fix(http): align default middleware order - #2261

Merged
Vincent Biret (baywet) merged 3 commits into
mainfrom
fix/native-http-middleware-order
Nov 24, 2026
Merged

Vincent Biret (baywet) merged 3 commits into
mainfrom
fix/native-http-middleware-order

Conversation

@baywet

Copy link
Copy Markdown
Member

Summary

  • Align the existing OkHttp middleware with the recommended order in docs: standardize native HTTP middleware order microsoftgraph/msgraph-sdk-design#124. Authorization stays opt-in for standalone requests; OkHttp retains native response decompression.
  • Inspect headers for each send, after redirect and retry decisions. Replay a same-origin claims challenge at the challenged hop and do not reauthorize a redirected request whose credentials were stripped.

Validation

  • gradlew.bat --no-daemon :components:http:okHttp:test
  • Regression coverage for factory order, retry/inspection on a redirect hop, and same- versus cross-origin claims challenges.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e625fa94-4ae9-464b-8e28-fddf64a8999d
@baywet
Vincent Biret (baywet) requested a review from a team as a code owner November 24, 2026 15:23
Copilot AI balanced review requested due to automatic review settings November 24, 2026 15:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active middleware defects leave incorrect retry-attempt headers on redirected requests and place downstream observability spans outside the authorization span.

2 open issues
What changed in this PR

Aligns Kiota’s default OkHttp middleware order with the recommended pipeline and updates authorization challenge handling for redirected requests.

Changes:

  • Runs header inspection after redirect and retry handling, while keeping authorization opt-in.
  • Replays same-origin claims challenges at the challenged hop without reauthorizing redirects whose credentials were stripped.
  • Documents the pipeline and adds regression tests for ordering, retries, inspection, and claims challenges.
File Description
README.md Documents middleware order, opt-in authorization, and native decompression.
components/​http/​okHttp/​src/​test/​java/​com/​microsoft/​kiota/​http/​middleware/​AuthorizationHandlerTest.java Tests same-origin challenge replay and cross-origin credential protection.
components/​http/​okHttp/​src/​test/​java/​com/​microsoft/​kiota/​http/​KiotaClientFactoryTest.java Verifies interceptor order and redirected-hop retry inspection.
components/​http/​okHttp/​src/​main/​java/​com/​microsoft/​kiota/​http/​middleware/​AuthorizationHandler.java Guards challenge replay and uses the challenged request.
components/​http/​okHttp/​src/​main/​java/​com/​microsoft/​kiota/​http/​KiotaClientFactory.java Reorders middleware and inserts optional authorization before redirects.

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e625fa94-4ae9-464b-8e28-fddf64a8999d
Copilot AI balanced review requested due to automatic review settings November 24, 2026 15:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The claims replay preserves a stale Retry-Attempt header despite restarting the retry counter, causing reported attempt counts to become inconsistent and decrease on subsequent retries.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Clear stale retry-attempt header before claims replay

components/​http/​okHttp/​src/​main/​java/​com/​microsoft/​kiota/​http/​middleware/​AuthorizationHandler.java:128

Copying the challenged request also preserves Retry-Attempt from the completed retry invocation, but the claims replay starts a new RetryHandler invocation with a fresh counter. For a 429 → 429 → 401 (claims) → 429 → 200 sequence, the headers become absent, 1, 2, 2, 1: the first claims replay reports a stale attempt count, and its next retry decreases it. Please clear the retry header when preparing the claims replay, just as at the redirect boundary, so transmitted and inspected headers match the fresh retry counter.

2 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e625fa94-4ae9-464b-8e28-fddf64a8999d
Copilot AI balanced review requested due to automatic review settings November 24, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the middleware-order and claims-challenge updates.

No open issues 🎉

Review effort: Balanced

@baywet
Vincent Biret (baywet) added this pull request to the merge queue Nov 24, 2026
@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Nov 24, 2026
Merged via the queue into main with commit 45c041d Nov 24, 2026
9 checks passed
@baywet
Vincent Biret (baywet) deleted the fix/native-http-middleware-order branch November 24, 2026 19:13
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

3 participants