Skip to content

Add User-Agent header to file upload requests#37

Merged
Fivell merged 2 commits intomainfrom
fix/upload-user-agent
Mar 11, 2026
Merged

Add User-Agent header to file upload requests#37
Fivell merged 2 commits intomainfrom
fix/upload-user-agent

Conversation

@Fivell
Copy link
Member

@Fivell Fivell commented Mar 10, 2026

Summary

  • Added User-Agent header to uploadEncryptedFile() request
  • Upload was using a separate HttpClient without the ApiKeyInterceptor

Test plan

  • Test verifies User-Agent header is sent
  • All tests pass

@Fivell Fivell force-pushed the fix/upload-user-agent branch from ba15f77 to 9972cdd Compare March 10, 2026 22:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR ensures encrypted file uploads include the SDK User-Agent header, aligning multipart upload requests with the headers normally applied by the main OkHttpClient interceptor chain.

Changes:

  • Add User-Agent: didww-java-sdk/<version> to DidwwClient.uploadEncryptedFile() requests.
  • Extend WireMock verification in the existing upload test and add a new test asserting the exact User-Agent value.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/main/java/com/didww/sdk/DidwwClient.java Adds User-Agent header to the multipart upload request.
src/test/java/com/didww/sdk/EncryptedFileUploadTest.java Verifies User-Agent is sent for encrypted file uploads (regex + exact-value test).
Comments suppressed due to low confidence (1)

src/main/java/com/didww/sdk/DidwwClient.java:232

  • uploadEncryptedFile() creates a brand-new OkHttpClient and only copies timeouts. This drops any advanced configuration applied to the main client (proxy, SSL settings, connection pool, DNS, user-provided interceptors via httpClientBuilder, etc.), so uploads may behave differently from other requests. Consider building from httpClient.newBuilder() and removing only the ApiKeyInterceptor (or replacing it with a headers-only interceptor) so uploads preserve the caller's OkHttp configuration while still avoiding JSON:API headers for multipart.
                .header("User-Agent", SdkVersion.userAgent())
                .build();

        // Dedicated client without JSON:API interceptor, preserving timeouts from main client.
        OkHttpClient uploadClient = new OkHttpClient.Builder()
                .connectTimeout(httpClient.connectTimeoutMillis(), TimeUnit.MILLISECONDS)
                .readTimeout(httpClient.readTimeoutMillis(), TimeUnit.MILLISECONDS)
                .writeTimeout(httpClient.writeTimeoutMillis(), TimeUnit.MILLISECONDS)
                .build();

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +46 to +63
@Test
void testUploadEncryptedFileSendsUserAgent() {
wireMock.stubFor(post(urlPathEqualTo("/v3/encrypted_files"))
.willReturn(aResponse()
.withStatus(201)
.withHeader("Content-Type", "application/json")
.withBody(loadFixture("encrypted_files/create.json"))));

client.uploadEncryptedFile(
"example".getBytes(StandardCharsets.UTF_8),
"sample.pdf.enc",
"fingerprint-123",
"sample.pdf"
);

wireMock.verify(postRequestedFor(urlPathEqualTo("/v3/encrypted_files"))
.withHeader("User-Agent", equalTo(SdkVersion.userAgent())));
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

testUploadEncryptedFile() now asserts the User-Agent header, and testUploadEncryptedFileSendsUserAgent() repeats the same behavior with a separate stub + verify. This duplication increases test maintenance without adding new coverage. Consider asserting the exact header value (SdkVersion.userAgent()) in the existing test and removing the extra test (or differentiating the new test to cover a distinct scenario).

Copilot uses AI. Check for mistakes.
wireMock.verify(postRequestedFor(urlPathEqualTo("/v3/encrypted_files"))
.withHeader("Api-Key", equalTo("test-api-key"))
.withHeader(ApiKeyInterceptor.API_VERSION_HEADER, equalTo(ApiKeyInterceptor.API_VERSION))
.withHeader("User-Agent", matching("didww-java-sdk/.*"))
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The User-Agent assertion in testUploadEncryptedFile() uses a very permissive regex (didww-java-sdk/.*), which can mask regressions in the exact header value. If the intent is to verify the SDK sends the canonical value, prefer equalTo(SdkVersion.userAgent()) (and then you can avoid needing a separate test for exactness).

Suggested change
.withHeader("User-Agent", matching("didww-java-sdk/.*"))
.withHeader("User-Agent", equalTo(SdkVersion.userAgent()))

Copilot uses AI. Check for mistakes.
Replace permissive regex matching with equalTo(SdkVersion.userAgent())
in testUploadEncryptedFile and remove redundant
testUploadEncryptedFileSendsUserAgent test method.
@sonarqubecloud
Copy link

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Fivell Fivell merged commit 7046a34 into main Mar 11, 2026
9 checks passed
@Fivell Fivell requested a review from Copilot March 11, 2026 09:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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