Skip to content
This repository has been archived by the owner on Mar 25, 2019. It is now read-only.

Re-worked request interception to configure itself as the default system proxy #3

Merged
merged 2 commits into from
Nov 13, 2014

Conversation

davidwhitney
Copy link
Contributor

When the server starts, the system proxy registers itself, and unmodified calls to any Url can be hooked and intercepted.
Currently only tested against the existing WebRequest test cases - need to verify against other libraries. Anything that respects the system proxy configuration should work unfettered. Original "direct" use-case still works correctly.

Apologies for the horrible line endings conversion in the FakeServerScenarios - file had inconsistent endings.

Breaking changes: FakeServer is now configured with just a port, as it hosts on 127.0.0.1 instead of a hostname.
New Features:

    [Fact]
    public void FakeServer_RequestingAUriThatHasNotBeenModified_ResponseMatchesExpectation()
    {
        using (var fakeServer = new FakeServer(12354))
        {
            fakeServer.Expect.Get("/123").Returns("Some String Data");
            fakeServer.Start();

            var result = new WebClient().DownloadString(new Uri("http://www.bing.com/123"));

            result.Should().Be("Some String Data");
        }
    }

Works.

…tem proxy.

When the server starts, the system proxy registers itself, and unmodified calls to any Url can be hooked and intercepted.
Currently only tested against the existing WebRequest test cases - need to verify against other libraries. Anything that respects the system proxy configuration should work unfettered.

Original "direct" use-case still works correctly.
@davidwhitney
Copy link
Contributor Author

(Added two test scenarios to cover this "proxied" usage).

@davidwhitney
Copy link
Contributor Author

As a further enhancement, we could also enforce full canonical url matching, to avoid clashes with common uri paths. The most obvious case is that at the moment "/" would be a little confusing.

private IWebProxy _initialProxy;
private RequestCachePolicy _initialCachePolicy;

public FakeServer(int basePort)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want to keep the existing behaviour without the proxy for some test cases and existing test code we've already got.
So the constructor that only takes a port number should change the proxy setting. The original constructor, that takes the baseUri should not register any proxies.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking, you don't even need to specify the port number in the proxy case. Just assume it is 12354 or whatever as it does not matter to the clients.
We'll have to detect port collisions at some point but that is another issue.

@davidwhitney
Copy link
Contributor Author

Clever, I like the concept, have both behaviours.

cosminonea added a commit that referenced this pull request Nov 13, 2014
Re-worked request interception to configure itself as the default system proxy
@cosminonea cosminonea merged commit 041e395 into justeat:master Nov 13, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants