Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

WebRequest.DefaultWebProxy: Set doesn't work without a previous Get #22798

Merged
merged 4 commits into from
Jul 31, 2017

Conversation

arunjvs
Copy link
Contributor

@arunjvs arunjvs commented Jul 31, 2017

Iteration1: #22720.
Added test case as per comments in iteration1.

Unless we do an unnecessary Get() on WebRequest.DefaultWebProxy, any Set() done will not be honored.

This is especially a problem on Linux, where DefaultWebProxy throws PlatformNotSupportedException(). This in turn breaks libraries like WindowsAzure.Storage which fail unless the Get() is called first and then WebRequest.DefaultWebProxy is set to null.

This fix avoids the unnecessary Get() by setting the already initialized flag sent to the LazyInitializer.

@davidsh @stephentoub

@dnfclas
Copy link

dnfclas commented Jul 31, 2017

@arunjvs,
Thanks for your contribution.
To ensure that the project team has proper rights to use your work, please complete the Contribution License Agreement at https://cla2.dotnetfoundation.org.

It will cover your contributions to all .NET Foundation-managed open source projects.
Thanks,
.NET Foundation Pull Request Bot

Copy link
Contributor

@davidsh davidsh left a comment

Choose a reason for hiding this comment

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

Please review feedback.

// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.Net.Test.Common
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be the namespace for this class since this file is not in the Common\src directory. It should be the same namespace as the other test files in this folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -3,47 +3,19 @@
// See the LICENSE file in the project root for more information.

using System.Diagnostics;

using System.Net.Test.Common;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this once you fix up the DummyWebProxy.cs file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

<Compile Include="HttpWebRequestTest.cs" />
<Compile Include="HttpWebResponseTest.cs" />
<Compile Include="RequestStreamTest.cs" />
<Compile Include="WebRequestTest.cs" />
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you moving these lines? It isn't necessary as part of this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Organizing the csproj itemgroups. Let me know if it's not desirable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this change. In general, you should keep your changes small and specific to the bug you are wishing to fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@davidsh davidsh changed the title WebRequest.DefaultWebProxy: Set doesn't work without a previous Get: Iteration2 WebRequest.DefaultWebProxy: Set doesn't work without a previous Get Jul 31, 2017
@dnfclas
Copy link

dnfclas commented Jul 31, 2017

@arunjvs, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request.

Thanks, .NET Foundation Pull Request Bot

<Compile Include="HttpWebRequestTest.cs" />
<Compile Include="HttpWebResponseTest.cs" />
<Compile Include="RequestStreamTest.cs" />
<Compile Include="WebRequestTest.cs" />
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this change. In general, you should keep your changes small and specific to the bug you are wishing to fix.

[Fact]
public void Select_Success()
{
RemoteInvoke(() =>
{
var myProxy = new MyWebProxy();
var myProxy = new DummyWebProxy();
Copy link
Member

Choose a reason for hiding this comment

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

Does it need to be an instance of a new class like this? Could it not just be a new WebProxy()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WebProxy looks too generic a name for a dummy implementation. It sounds more like a base class for IWebProxy.

Copy link
Member

@stephentoub stephentoub Jul 31, 2017

Choose a reason for hiding this comment

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

I'm not talking about a dummy implementation. There's already a fairly generic WebProxy class that exists... I'm saying let's use it rather than adding a new file with a new dummy type... just use the type that already exists.
https://github.com/dotnet/corefx/blob/master/src/System.Net.WebProxy/src/System/Net/WebProxy.cs#L13

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I realized it in indeed is. A separate dummy proxy still looks safe (keeping existing behavior in the tests). Let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand. Sure, it's safe. But it's unnecessary code. Why an unnecessary code to the repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay so should I keep GlobalProxySelectionTest as is with it's MyWebProxy or change it to WebProxy along with WebRequestTest?

Copy link
Contributor

Choose a reason for hiding this comment

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

Revert the change to GlobalProxySelectionTest.

Then try the simple "WebProxy()" change for your new test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Works with WebProxy().

@arunjvs
Copy link
Contributor Author

arunjvs commented Jul 31, 2017

Addressed comments and validated the test works with the change.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Thanks for the fix and test. LGTM.

@davidsh davidsh merged commit 6acd74d into dotnet:master Jul 31, 2017
@arunjvs arunjvs deleted the patch-1 branch August 1, 2017 08:19
@karelz karelz modified the milestone: 2.1.0 Aug 14, 2017
danmoseley pushed a commit to danmoseley/corefx that referenced this pull request Sep 8, 2017
…otnet#22798)

* WebRequest.DefaultWebProxy: Set doesn't work without a previous Get
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…otnet/corefx#22798)

* WebRequest.DefaultWebProxy: Set doesn't work without a previous Get


Commit migrated from dotnet/corefx@6acd74d
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants