Skip to content
This repository was archived by the owner on Dec 16, 2023. It is now read-only.

Enable HTTPS for pass-through requests #60

Closed
wants to merge 1 commit into from
Closed

Enable HTTPS for pass-through requests #60

wants to merge 1 commit into from

Conversation

chanderson0
Copy link

Re-enables SSL tests - fixing at least #46

@assaf
Copy link
Owner

assaf commented Mar 25, 2015

This will fail badly on io.js/0.12 because HTTPS.request basically calls HTTP.request to do all the work, ending up in infinite recursion.

@sudothinker
Copy link

Yep, ends up in an infinite loop, mentioned that here - #46.

Any ideas to get around this @assaf ?

@assaf
Copy link
Owner

assaf commented Mar 26, 2015

Is there a way to use http.request in Node 0.10 when making HTTPS requests?

@chanderson0
Copy link
Author

Doubt it. The v0.10.x HTTPS has a private createConnection method that is assigned to the Agent in v0.12.x. You could duplicate that behavior in this code, but since the API has actually changed it'll be easier to just call the methods as intended, I think.

I added a version check which fixes the problem at hand, but it didn't pass tests as process.version isn't set on Travis CI. Will dig a little deeper...

@sudothinker
Copy link

I tried using this code branch (with HTTP.ClientRequest). When using an https endpoint I still get:

     Uncaught Error: Protocol "http:" not supported. Expected "https:".

Whenever I add a hacky tweak to force the protocol: sudothinker@fa6efe7. I now get:

     Error: Timeout: did not get to load all resources on this page
      at timeout (/zombie/lib/eventloop.js:543:36)
    // We gave up, could be result of slow response ...
    function timeout() {
      if (eventLoop.expected) done(new Error("Timeout: did not get to load all resources on this page"));else done();
    }

Not too sure why that second comes in, still investigating. I'm using node 0.12.1, replay 2.0.4 and zombie 3.1.0

@assaf
Copy link
Owner

assaf commented Mar 26, 2015

FYI each protocol has a default port, but the port number doesn't dictate the protocol, so the URL http://localhost:443 should make an HTTP request over port 443. And url.port returns null unless the URL specifies a port.

So my guess is this code is trying to make an HTTP request, there's a lot of prep work that happens in http.request that gets bypassed by just constructing ClientRequest which causes the code to fail early, it never calls the callback, so the request just times out.

@sudothinker
Copy link

Yeh I know that the port doesn't define the protocol, i just added that in so I could try forcing the https protocol. The resulting options which cause the timeout to HTTP.ClientRequest are:

{ protocol: 'https:',
  hostname: 'hostname',
  port: '443',
  path: '/path',
  method: 'POST',
  headers: 
   { 'user-agent': 'node-soap/0.2.0',
     accept: 'text/html,application/xhtml+xml,application/xml',
     'accept-encoding': 'none',
     'accept-charset': 'utf-8',
     connection: 'close',
     host: 'hostname',
     'content-length': '828',
     'content-type': 'text/xml; charset=utf-8'},
  agent: 
   { domain: null,
     _events: { free: [Function] },
     _maxListeners: undefined,
     defaultPort: 443,
     protocol: 'https:',
     options: { path: null },
     requests: {},
     sockets: {},
     freeSockets: {},
     keepAliveMsecs: 1000,
     keepAlive: false,
     maxSockets: Infinity,
     maxFreeSockets: 256 },
  auth: undefined }

@assaf
Copy link
Owner

assaf commented Mar 26, 2015

In 0.12/io.js the only thing you need to get HTTPS working is to make sure the Agent is HTTPS, which clearly is in your example. That's the only material difference between HTTP and HTTPS requests, see: https://github.com/joyent/node/blob/master/lib/https.js#L131

0.10 always required a bit more code to setup HTTPS requests: https://github.com/joyent/node/blob/v0.10.36-release/lib/https.js#L95-L124

@sudothinker
Copy link

Right, I even tried forcing the agent too: options.agent = HTTPS.globalAgent; but still getting this timeout. I'm running node 0.12.1.

I can keep digging, it doesn't even seem to be running that long before it timeouts and I have zombie maxWait set to 25s

assaf added a commit that referenced this pull request Mar 27, 2015
@assaf
Copy link
Owner

assaf commented Mar 27, 2015

Just pushed this to master, SSL tests now happening, works well on io.js.

@sudothinker
Copy link

Still no luck on node 0.12.1.

I actually just tried it on io.js 1.6.2 and got the same problems. (either wrong protocol, or a timeout if you force the protocol).

By default it looks like the options being passed to ClientRequest have options.protocol: "http:" but options.agent.protocol: "https:"

@assaf
Copy link
Owner

assaf commented Mar 27, 2015

Currently test suite passed on 0.10, 0.12 and io.js: https://travis-ci.org/assaf/node-replay (it was passing before, apparently by not running any of the code we're talking about)

I have, however, no idea how/why the code works with 0.10.

@djanowski
Copy link
Collaborator

@sudothinker Maybe this is fixed by #62?

@assaf assaf closed this Apr 7, 2018
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.

4 participants