Skip to content

feat: add Apache HttpClient 5.x adapter support#3613

Closed
uuuyuqi wants to merge 2 commits intoalibaba:masterfrom
uuuyuqi:feat/apache-httpclient5-adapter
Closed

feat: add Apache HttpClient 5.x adapter support#3613
uuuyuqi wants to merge 2 commits intoalibaba:masterfrom
uuuyuqi:feat/apache-httpclient5-adapter

Conversation

@uuuyuqi
Copy link
Copy Markdown
Collaborator

@uuuyuqi uuuyuqi commented Apr 28, 2026

Describe what this PR does / why we need it

Add a new sentinel-apache-httpclient5-adapter module to support flow control for outgoing HTTP requests made with Apache HttpClient 5.x.

Apache HttpClient 5.x has been the recommended version since 2020, and 4.x is now in maintenance mode. This PR adds first-class support for the 5.x API.

Does this pull request fix one issue?

Fixes #3612

Describe how you did it

Module structure (sentinel-adapter/sentinel-apache-httpclient5-adapter):

  • SentinelApacheHttpClient5Handler — Implements ExecChainHandler to intercept outgoing requests in the HttpClient 5.x exec chain. Uses SphU.entry() for Sentinel resource entry with EntryType.OUT.
  • SentinelApacheHttpClientConfig — Configuration class with pluggable prefix, resource extractor, and fallback.
  • ApacheHttpClientResourceExtractor / DefaultApacheHttpClientResourceExtractor — Resource name extraction. Default format: METHOD:url with query string and fragment stripped (consistent with the existing OkHttp adapter).
  • ApacheHttpClientFallback / DefaultApacheHttpClientFallback — Fallback on block. Default throws SentinelRpcException.

Key design decisions:

  1. Uses ExecChainHandler interface — the idiomatic HttpClient 5.x interception mechanism, replacing the decorateMainExec approach used in the 4.x adapter.
  2. Resource name format METHOD:url — consistent with the existing sentinel-okhttp-adapter convention, and auto-strips query/fragment for stable resource keys.
  3. Empty resource name bypass — if extractor returns null/empty, Sentinel protection is skipped.
  4. Minimum HttpClient version 5.1 (provided scope).

Describe how to verify it

  1. Build: mvn compile -pl sentinel-adapter/sentinel-apache-httpclient5-adapter -am
  2. Test: mvn test -pl sentinel-adapter/sentinel-apache-httpclient5-adapter
  3. All 21 tests pass (7 unit tests for extractor/config/fallback + 5 integration tests with Spring Boot + 9 from extractor combinations).

Usage example:

CloseableHttpClient httpclient = HttpClients.custom()
    .addExecInterceptorBefore(ChainElement.MAIN_TRANSPORT.name(), "sentinel",
        new SentinelApacheHttpClient5Handler())
    .build();

Special notes for reviews

  • The extension point interfaces (ApacheHttpClientResourceExtractor, ApacheHttpClientFallback) follow the same pattern as the existing 4.x adapter and OkHttp adapter.
  • The DefaultApacheHttpClientResourceExtractor uses request.getUri().toString() which returns the full URL in the exec chain context. Query parameters and fragments are stripped for stable resource naming.
  • HttpClient 5.x dependency is provided scope — users bring their own version (5.1+).

Made with Cursor

Add sentinel-apache-httpclient5-adapter module to support flow control
for Apache HttpClient 5.x outgoing HTTP requests. The adapter implements
ExecChainHandler to intercept requests in the HttpClient exec chain.

Key features:
- SentinelApacheHttpClient5Handler: ExecChainHandler implementation
- Default resource name format: METHOD:url (query/fragment stripped)
- Pluggable resource extractor and fallback interfaces
- Comprehensive unit and integration tests

Change-Id: I6be84c73078102a92c5701cce9f66e1c543f32f7
Co-developed-by: Cursor <noreply@cursor.com>
…L XSS alert

Change-Id: Idadec9e77dbebc0d64dee5bd873b4c47b42f4048
Co-developed-by: Cursor <noreply@cursor.com>
@uuuyuqi
Copy link
Copy Markdown
Collaborator Author

uuuyuqi commented Apr 28, 2026

Closing this PR as it was incorrectly based on master (2.0.0-alpha2-SNAPSHOT). Re-submitting against the bump-version-1.8.10-snapshot branch.

@uuuyuqi uuuyuqi closed this Apr 28, 2026
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.

2 participants