Git Product home page Git Product logo

browser-request's People

Contributors

astro avatar fb55 avatar jhs avatar khrome avatar max-mapper avatar perezd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

browser-request's Issues

Request works in Chrome, fails in Firefox with "CORS request rejected" error

In Chrome the following code works.
In Firefox I get the error :
Error: CORS request rejected
With the code :

use strict';
var request =require('browser-request');
var url = 'http://docs.google.com/spreadsheets/export?id=1-on_GfmvaEcOk7HcWfKb8B6KFRv166RkLN2YmDEtDn4&exportFormat=csv';
request(url, function (error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log('success fetch');
        console.log(response.statusCode);
        console.log(body);
    }else{
        console.log(error + ' ' + response.statusCode );
    }
});

merge in to mikeal/request

we should think about a strategy for merging this in to the main request repository.

there is a good amount of code now that can be shared, the OAuth signing code in particular.

i'd also like new options that people write for node-request to go in to the browser version.

json:true writes to body even if there's nothing to write

when I mark json:true, I see the body is written.

this makes the code not compatible with node version.
in node version I mark json:true to get the response as json. I don't send anything on the body, and I must not write anything on the body (the REST API I use fails if I do, as it expects an empty body).

Error on empty response

In Chrome, I get "Syntax Error: Unexpected end of input" when the server returns nothing.

Steps to reproduce:

request({
  ...
  method: "POST",
  json: { my: "data" }
}, ...);

When the server returns a 204, it doesn't return any data with it. However, line 215 tries to parse the empty string as JSON, which causes the error in Chrome.

What is the best way for me to POST some JSON, but expect nothing in return? Using the json key always expects a JSON response from the server?

Basic authentication options are incompatible with request lib

In the original request lib, to use basic authentication you set auth.user and auth.pass in options

request.get('http://some.server.com/', {
  'auth': {
    'user': 'username',
    'pass': 'password',
    'sendImmediately': false
  }
});

Ref: https://www.npmjs.com/package/request#http-authentication

But browser-request expectsauth.username and auth.password. See

options.headers.authorization = 'Basic ' + b64_enc(options.auth.username + ':' + options.auth.password);

This breaks compatibility between the two libs.

better cross domain errors

Given a cross domain request:

request({url: "http://pizza.com/api"}, function(e,r,b) {
  console.log(e,r,b)
})

e and b are null

request({url: "http://pizza.com/api", json:true}, function(e,r,b) {
  console.log(e,r,b)
})

e is a JSON parse syntax error and b is null

Would it be possible to detect and return an error about the single origin policy?

Simple way to make a request sync?

By default browser-request is async but I don't see any obvious way to make it sync. I have two functions, getHTTP and HTTPExists, but I also want to make getHTTPSync and HTTPExistsSync.

What are my options to make them sync?

function HTTPExists(url, cb) {
  request({ url: resolve(url), method: 'HEAD' }, function(err, res) {
    if (err) return cb(null, false);
    cb(null, /4\d\d/.test(res.statusCode) === false);
  });
}
function getHTTP(url, cb) {
  request(resolve(url), function (error, response, body) {
    if (!error && response.statusCode == 200) {
      cb(null, body);
    } else {
      cb(error, body)
    }
  })
}

Broken in FF, How do you run tests?

browser-request is broken in FF, due to the following code:

for (key in window) // XMLHttpRequest is not enumerated in FF
    if(window.hasOwnProperty(key))
      win[key] = window[key]

  run_code()

  for (key in window)
    if(window.hasOwnProperty(key))
      if(window[key] !== win[key]) {
        exports[key] = window[key] // ... therefore it's never exported here
        window[key] = win[key]
      }
// therefore the exports object is empty and this throws
var xmlhttprequest = require('./xmlhttprequest')
if(!xmlhttprequest || typeof xmlhttprequest !== 'object')
  throw new Error('Could not find ./xmlhttprequest')

This currently breaks voxel-gist in FF (cc @maxogden).

I'd like to submit a PR, but can't figure out how to run tests. rake test fails because it's trying to hit http://localhost:5984/test-browser-request, which I have no idea how to create.

Also, before attempting a fix, I wanted to ask why the for ... in loop was being used at all, because I believe XMLHttpRequest (the library, not the built-in) only exports XMLHttpRequest, meaning the exports are known. Unless there are others that I don't know about?

Support CORS

Needs a good way to test.

In request_jquery, there was options.creds or options.withCredentials which would set "xhrFields": { "withCredentials": true } to the jQuery.ajax call.

Content-Type is application/json,application/json

If I specify 'json:true' and 'headers: { 'Content-Type' : 'application/json' }

the outgoing Content-Type header value is application/json,application/json.

I need to be able to override the Content-Type completely.
if header Content-Type is specified, you should ignore it and not modify it.

Uncaught error, no options given

I'm using it like:

var request = require('browser-request');

request('/blah', (err, resp, body) => {

});

But in the browser console, I get the uncaught exception "Error: no options given". However, according to the documentation, I don't need to give any options for a fetch request??

Why isn't followRedirect / followRedirects supported?

It seems to me, that requests made with browser-requests never follow redirects, but rather return the 30x response.

I just found the source for the error, that it's not supported:

var unsupported_options = ['proxy', '_redirectsFollowed', 'maxRedirects', 'followRedirect']

Could you please document / mention the reason why it's not supported?

(And for those wanting redirect support I suppose we have to handle the 30x response ourselves, right?)

Is anyone still maintaining this library?

With 30 Issues Opened and 31 Pull requests, I am wondering if this library is still maintained by anyone and if not, what could be the implications of using it in the long-term?

Require issues (browserify)

Hi

Thanks for this convenient library that allows me to use a single codebase on browser & node! I'm using this with browserify, but I've had to remove a few things from request.js:

  • require('./xmlhttprequest') — that file is not in the current directory
  • The check for XHR.name !== 'cXMLHttpRequest'
  • I also added a browserify key to package.json. A main key would help as well here.

Do you understand the issues or do you want me to draft a pull request?

Support proxy option

Hi there, how hard would it be to support proxy option, that is supported in the node request?

I was thinking, we would just need to replace the host address in URL of each request with the proxy host/ip address and it should work, am I wrong?

Use case: We're trying to switch from request to browser-request because of HTTP/2 support. We use this in Electron, so we have both node and browser environments.

window.request is undefined

Following the Usage instructions it seems like I should be able to avoid using Browserify by loading the browser-request JS file directly in HTML like so <script src="node_modules/browser-request/index.js"></script> and then in another JS file that is loaded beneath it, using browser-request by calling window.request (HTML comment in Usage instructions reads "Assigns the module to window.request"). Apparently I am misinterpreting that because window.request is undefined. Can someone please explain to me how to use this without needing to use Node's require() and Browserify? I have confirmed that node_modules/browser-request/index.js is being loaded by the browser.

Thank you.

encoding support in options

The latest request has an option 'encoding' which allows getting files as buffers or at least, bypassing the conversion to unicode. This option is not present in browser-request not does it warn the user about it.

Sending an image file using the form?

Some encoding issue

---------------------------------702453823
Content-Disposition: form-data; name="profile_picture"

[object Object]
---------------------------------702453823--

0.20 not working with ender

Requires are failing for me using ender and 0.20

request = require('browser-request');
and
request = require('request')

failing with
Ender Error: Requested module 'browser-request' has not been defined.
and
Ender Error: Requested module 'request' has not been defined.

here's my ender build header

/*!

  • =============================================================
  • Ender: open module JavaScript framework (https://ender.no.de)
  • Build: ender build underscore backbone qwery bonzo bean domready bowser ender-bootstrap ender-json browser-request morpheus traversty upload littering hamljs
  • =============================================================
    */

Support options.cache

Need to check if real request does this. I doubt it does.

The philosophical question becomes, duplicate the request API, or emulate the request API. In other words, cache-busting is probably going to be necessary to make it feel like Node.

Typescript support

Do you have any plan to support Typescript typings and / or ES6 modules?

request module work in browser

hi,
I tried the normal request module and browserified it. Everything worked fine in the browser.
Am I missing something? Why would one use browser-request instead of request?

Thank you

IE11 InvalidErrorStatus

Using the browser-request module in IE11 causes an InvalidStateError to occur.

The request code looks like this:

var options = {
   url: "....",
   json: true,
   timeout: 2000
};
request.get(options, function(err, res, obj) {
   // Error occurs before here
});

I have a nodejs module that requires the "request" module which on the browser (via browserify) uses the browser-request module. I've mapped this module correlation in my package.json like this:

  "browser": {
    "request": "browser-request"
  }

Note that the request actually appears to work just fine, but IE logs an error

Here is a screenshot of the error in IE11 Developer Tools

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.