aws / aws/aws-sdk-java-v2

No user-agent set when communicating via proxy

Open
#1,457 4 comments 0 reactions 0 assignees View on GitHub
bug hacktoberfest p3 proxy
Dominant language
Java
Stars
2.6k
Forks
1k
Avg merge
2d 9h
Merged PRs (30d)
51

Description

## Expected Behavior
When communicating via an explicit (non-transparent) HTTP Proxy, the User-Agent header should be set to something like `aws-sdk-java/whatever...` (see `UserAgentUtils.UA_STRING` for the template)

## Current Behavior
The User-Agent header is set to an empty string:
```
http-outgoing-1 >> "CONNECT sts.us-east-1.amazonaws.com:443 HTTP/1.1[\r][\n]"
http-outgoing-1 >> "Host: sts.us-east-1.amazonaws.com[\r][\n]"
http-outgoing-1 >> "User-Agent: [\r][\n]"
http-outgoing-1 >> "[\r][\n]"
http-outgoing-1 << "HTTP/1.1 200 Connection established[\r][\n]"
http-outgoing-1 << "[\r][\n]"
```
I believe this is due to the `.setUserAgent("")` in `ApacheHttpClient.createClient()`.

## Possible Solution
It would be nice for the User-Agent header to be set to something sensible _in the client itself_ instead of the empty string (as outlined above). Later on in the (normal) request processing, the AWS SDK will set the User-Agent header itself, but that's only for the portion of the request that it actually handles (i.e. the SDK explicitly sets the header when making a request, whereas the `setUserAgent()` sets a property on the client itself, and that property is needed by HttpClient when talking to a proxy).

## Steps to Reproduce (for bugs)
1. Set up a proxy server
2. Tell the SDK to use the proxy (either using the JDK standard System Properties or by setting `proxyConfiguration()` on the `ApacheHttpClient`'s builder)
3. Make a request to an AWS service (I used STS)
4. Notice that an empty string is sent for the User-Agent header (either by looking at the HttpClient's debug logs, or asking the proxy server to dump the traffic)

## Context
Proxy servers may handle requests different depending on a number of factors, including the User Agent. Without an accurate User Agent header, proxy servers lose an important piece of information.

## Your Environment
* AWS Java SDK version used: 2.9.14
* JDK version used: 1.8.x
* Operating System and version: Windows

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.