Skip to content
This repository was archived by the owner on Feb 28, 2019. It is now read-only.

Add bypass to node and xhr#20

Open
ponelat wants to merge 5 commits intoalgolia:masterfrom
ponelat:feature/bypass
Open

Add bypass to node and xhr#20
ponelat wants to merge 5 commits intoalgolia:masterfrom
ponelat:feature/bypass

Conversation

@ponelat
Copy link
Copy Markdown
Contributor

@ponelat ponelat commented Jul 25, 2016

This is an attempt at a bypass method which follows on #12
It adds it to node and xhr ( i couldn't manually test IE, so I left XDomainRequest).

Working with the XHR native, was a real gnarly one. I had initially hoped to put in the prototype chain, but I couldn't inherit from it. I tried running the xhr methods on a non-xhr instance and failed that too. I think an actual DOM element is made for XHR, but that's just a thought.

Nodejs was simple, but we don't get the whole request. Just the url, which mitm wants to create a socket on. This is the one I actually need. I was hoping for a uniform PR, to include to all other interface.

I'll check back here to cleanup the PR as needed, there might be some travis errors...

@ponelat
Copy link
Copy Markdown
Contributor Author

ponelat commented Jul 25, 2016

I'll take a look at the fails, soon as I'm able.

PS: Forget to mention how this would work...

  • Introduced a new event pre-request, which will have a single arg
  • The arg will be the request, or a bare bones url ( from nodejs )
  • The arg will also have a .bypass method, which when called will set a flag on the request instance
  • Then req.send() is called, presence of req._bypass will...
    • ...use the real methods to create an ajax/http request
    • ... fire the request, and copy the results onto the fakeRequest instance ( in the case of nodejs, a full bypass occurs )

@vvo
Copy link
Copy Markdown
Contributor

vvo commented Jul 25, 2016

The failed tests might just be a bad state in the browser testing stack. If you had them passing locally in a browser then we could move further.

Can you add some API documentation? Thanks

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