Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for proxy servers... #27

Closed
nfreear opened this issue Jan 7, 2015 · 5 comments
Closed

Add support for proxy servers... #27

nfreear opened this issue Jan 7, 2015 · 5 comments
Labels

Comments

@nfreear
Copy link
Contributor

nfreear commented Jan 7, 2015

(Not reverse-proxy)

Hi,

I think we'd need to integrate superagent-proxy - how to make this optional?

Ideas?

Thanks,

Nick

@nfreear
Copy link
Contributor Author

nfreear commented Jan 7, 2015

Hmm, does this need adding to chai-http, or is something for the user of the module to integrate?

I think this may have changed from a feature request, into a question.

Would this work...?

var chai = require("chai")
  , chaiHttp = require('chai-http')
  , proxy = 'http://proxy.example.org:80';

chai.use(chaiHttp);

require('superagent-proxy')(chai);

chai
  .request('http://external.example.com')
  .get('/')
  .proxy(proxy)
  .end(function (res) {

});

@keithamus
Copy link
Member

Hey again @nfreear 😄. superagent-proxy needs access to the SuperAgent instance, which for chai-http is in chai.request.Test, so your example will almost work - but you need to change require('superagent-proxy')(chai); to require('superagent-proxy')(chai.request.Test);, so the full code:

var chai = require("chai")
  , chaiHttp = require('chai-http')
  , proxy = 'http://proxy.example.org:80';

chai.use(chaiHttp);

require('superagent-proxy')(chai.request.Test);

chai
  .request('http://external.example.com')
  .get('/')
  .proxy(proxy)
  .end(function (res) {

});

Let me know if this works for you and I'll close out the issue 😄

nfreear added a commit to nfreear/ou-media-player-test that referenced this issue Jan 8, 2015
@nfreear
Copy link
Contributor Author

nfreear commented Jan 8, 2015

Hi,

I haven't succeeded in getting it working so far. Fails with:

$ make test-proxy

/Users/ ... /ou-media-player-test/node_modules/superagent-proxy/index.js:97
  if (desc.get == getUrl && desc.set == setUrl) return; // already patched
          ^
TypeError: Cannot read property 'get' of undefined
    at setupUrl (/Users/ ... /ou-media-player-test/node_modules/superagent-proxy/index.js:97:11)
    at Function.proxy (/Users/ ... /ou-media-player-test/node_modules/superagent-proxy/index.js:68:3)
    at setup (/Users/ ... /ou-media-player-test/node_modules/superagent-proxy/index.js:50:18)

Note, you may need this workaround if npm install superagent-proxy fails,

Bit of a puzzle. Yours,

nick

@keithamus
Copy link
Member

@nfreear ok. This looks to be because we call our SuperAgent instance "Test" while this plugin is expecting "Request". Should be a simple enough change - simply add a line between 173-174 of request.js saying

module.exports.Request = Test;

And then your first example of chai.use(chaiHttp); should work. If it works, please submit a PR and I'll get it merged ASAP and reward you with a million internet points.

nfreear added a commit to nfreear/chai-http that referenced this issue Jan 8, 2015
nfreear added a commit to nfreear/chai-http that referenced this issue Jan 8, 2015
keithamus added a commit that referenced this issue Jan 9, 2015
Bug #27, Add support for proxy servers via "superagent-proxy"
nfreear added a commit to nfreear/ou-media-player-test that referenced this issue Jan 9, 2015
* Switch to a GitHub link for "chai-http" dependency - package.json
* --> Access the edge/pre-release version, not yet in http://npmjs.com
* chaijs/chai-http#27
* `page()` becomes a new function definition, wrapping a call to `proxy()`
@rjperry611
Copy link

For those who see this and don't want to change the module. I got it to work this way (for v1.0):

var chai = require("chai");
var chaiHttp = require("chai-http");
chai.use(chaiHttp);
chai.request.Request = chai.request.Test;
require('superagent-proxy')(chai.request);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants