Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off the automatic proxy detection in the `AmazonS3` object?

When using the AmazonS3 object for the first time after the application starts, there is a large delay of approx 14 seconds. This large time delay is not present for all subsequent calls.

I have encountered this exact delay issue before with other HTTP related classes and it is caused when the class in question tries to determine the local machine's proxy settings and whether to use them or not.

To stop this from happening with WebClient, you set WebClient.Proxy = null; and it doesn't try to auto detect the proxy settings, but I cannot figure out how to disable the proxy detection functionality of the AmazonS3 object.

I have specifically tried setting the ProxyHost to null:

_s3Client = AWSClientFactory.CreateAmazonS3Client(awsAccessKey, awsSecretAccessKey, new AmazonS3Config { ProxyHost = null });

Which didn't work. We are currently using the Amazon .NET SDK 'v1.3.17.0'.

Is there a way to turn off the proxy detection?

like image 801
InvertedAcceleration Avatar asked Jan 23 '12 11:01

InvertedAcceleration


People also ask

What is automatic proxy detection?

Automatic proxy detection is a process by which a Web proxy server is identified by the system and used to send requests on behalf of the client. This feature is also known as Web Proxy Auto-Discovery (WPAD).


1 Answers

Good question - I haven't tried it myself and only analyzed the code, but the AmazonS3Config Class uses a private method configureWebRequest(), which in turn relies on the WebRequest Class to handle the actual HTTP connection. Now, WebRequest has a WebRequest.DefaultWebProxy Property , which is public static (i.e. you can set this within your application before calling CreateAmazonS3Client(()) :

The DefaultWebProxy property gets or sets the global proxy. The DefaultWebProxy property determines the default proxy that all WebRequest instances use if the request supports proxies and no proxy is set explicitly using the Proxy property. [emphasis mine]

The proxy auto detection you are experiencing is supposedly induced by the respective IE behavior:

The DefaultWebProxy property reads proxy settings from the app.config file. If there is no config file, the current user's Internet Explorer (IE) proxy settings are used.

Consequently I'd hope that this can be disabled in a similar way as for the WebClient.Proxy Property you mentioned, albeit on the class level, as indeed strongly suggested by the last paragraph:

If the DefaultWebProxy property is set to null, all subsequent instances of the WebRequest class created by the Create or CreateDefault methods do not have a proxy. [emphasis mine]


Added by blexandre

sample code from this answer would be

System.Net.WebRequest.DefaultWebProxy = null;
_s3Client = AWSClientFactory.CreateAmazonS3Client(awsAccessKey, awsSecretAccessKey);

Note that this will disable the proxy for every web request, _client is created using it, so it is safe to do this, but be careful if you might have more requests pending from the WebRequest class

like image 69
Steffen Opel Avatar answered Sep 21 '22 18:09

Steffen Opel