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

does not allow testing with a String as the first parameter #34

Closed
keithamus opened this issue Apr 10, 2014 · 0 comments
Closed

does not allow testing with a String as the first parameter #34

keithamus opened this issue Apr 10, 2014 · 0 comments

Comments

@keithamus
Copy link

Abstract

Node-Replay does not support a String as the first parameter of http.get, and never actually proxies requests where the first argument is a String.

Details

As per the node.js documentation around http.get, a URL string can be passed instead of an options object. Node.js then uses url.parse to separate this out as needed. Therefore the following code should work:

http.get('http://google.com')

Node-Replay does not support this, it assumes options is an object. If the properties cannot be found on the object it defaults to passing isLocalhost - e.g:

var options = 'http://google.com';
var hostname = options.hostname || (options.host && options.host.split(":")[0]) || "localhost"
console.log(hostname); // "localhost"

This means using http.get with a String as the first argument results in Node-Reply not proxying the request.

Solution

Detecting if the first argument is a String, and converting it to the expected object - e.g typeof options === 'string' ? url.parse(options) : options is the best solution. If you'd like I can create a PR for this, but I don't have time to do it today (with tests).

@assaf assaf closed this as completed in c14b614 Apr 18, 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

No branches or pull requests

1 participant