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

Default protocol is inconsistent with Node's. #96

Open
recursify opened this issue Oct 29, 2015 · 2 comments
Open

Default protocol is inconsistent with Node's. #96

recursify opened this issue Oct 29, 2015 · 2 comments

Comments

@recursify
Copy link

If not specified, http-browserify sets the protocol to window.location.protocol. This differs from the behavior of Node (see https://nodejs.org/api/http.html#http_http_request_options_callback ). I assume the reasoning was to make https requests if the current location is also https (but I could be wrong here).

Does it make sense to mimic Node's behavior exactly, and just default to http: ?

The issue I'm running into is when running a script locally in the browser, so the protocol is "file:". http-browserify then tries to make file:// requests, which obviously fail.

@zallek
Copy link

zallek commented Feb 21, 2016

+1

@pmantaj
Copy link

pmantaj commented Sep 24, 2016

I experienced the same problem. I think that http-browserify sets the protocol to window.location.protocol in any case. I tried to call a request to my API, eg. http://<hostname>/api, so I specified the HTTP protocol and http-browserify still tries to send the request to file://<hostname>/api. The reason is that in the lib/request.js file URI is composed from scratch. Take a look:

    self.uri = (params.protocol || 'http:') + '//'
        + params.host
        + (params.port ? ':' + params.port : '')
        + (params.path || '/')
    ;

In my case, it does not work. I need the same URI that I put to a request method. I fixed it by adding a below line after code that I've posted above:

if (params.href !== 'undefined' && params.protocol === 'file:') self.uri = params.href;

It resolved a few problems in my project but I am not sure is this change will not cause breaking a code in another scenario.

pmantaj added a commit to pmantaj/http-browserify that referenced this issue Sep 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants