Skip to content

feat(http): Add pluggable HttpAdapter interface for HTTP transport#334

Draft
douglasmiller wants to merge 3 commits into
v3-v2021-02-25from
http-adapter
Draft

feat(http): Add pluggable HttpAdapter interface for HTTP transport#334
douglasmiller wants to merge 3 commits into
v3-v2021-02-25from
http-adapter

Conversation

@douglasmiller

Copy link
Copy Markdown
Contributor

Description

Introduce a pluggable HttpAdapter interface that decouples the Recurly Java client
from any specific HTTP library. Replace the previous OkHttp-based implementation with
a DefaultHttpAdapter built on Java's built-in HttpURLConnection, removing the OkHttp
dependency. Add automatic gzip decompression for HTTP responses and expose
ClientOptions.setHttpAdapter() so callers can inject a custom implementation.

Testing

Setup / Prerequisites:

  • Environment: local
  • JDK 8+ and Maven installed
  • No external services required — tests use contract tests and mocks

Happy Path:

  1. Run the full test suite: mvn test
    Expected: BUILD SUCCESS, 0 failures
  2. Instantiate ClientOptions with a custom HttpAdapter implementation and verify
    the client uses it instead of the default.
    Expected: custom adapter is called for each API request

Edge Cases / Error Cases:

  1. Response with Content-Encoding: gzip header
    Expected: body is transparently decompressed before parsing
  2. Custom adapter that throws an IOException
    Expected: wrapped in the appropriate Recurly exception type

Automated Test Coverage:

  • Run: mvn test
  • Key test classes: HttpAdapterContract, DefaultHttpAdapterContractTest,
    HttpResponseTest, BaseClientTest, HeaderInterceptorTest

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

douglasmiller and others added 3 commits June 30, 2026 13:20
Introduce HttpAdapter, HttpResponse, and DefaultHttpAdapter in the
com.recurly.v3.http package. DefaultHttpAdapter wraps OkHttp and owns
gzip negotiation, connection management, and timeout configuration.
BaseClient now builds its headers map directly and delegates all
transport to the injected adapter, removing the OkHttp dependency from
the SDK core. ClientOptions gains setHttpAdapter() as the injection
point. HeaderInterceptor is removed; its User-Agent logic moves to
BaseClient.

Co-Authored-By: Claude <noreply@anthropic.com>
Replace OkHttp transport with java.net.HttpURLConnection; remove okhttp
and logging-interceptor compile dependencies. Preserve debug logging
behind RECURLY_INSECURE + RECURLY_DEBUG using System.out.println.

Fix 411 errors on POST/PUT with null body by sending Content-Length: 0,
matching OkHttp prior behavior. Add contract tests for this case.

Update the implementation guide to use OkHttp as the example adapter
instead of java.net.http.HttpClient.

Co-Authored-By: Claude <noreply@anthropic.com>
Send Accept-Encoding: gzip on every request and transparently decompress
gzip-encoded responses in DefaultHttpAdapter. Covers both success and error
response bodies. Two new contract tests verify decompression end-to-end.

Co-Authored-By: Claude <noreply@anthropic.com>
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.

1 participant