-
-
Notifications
You must be signed in to change notification settings - Fork 11k
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
No buffer in browser #887
No buffer in browser #887
Conversation
The is-buffer module checks if an object is a Buffer without causing Webpack or Browserify to include the whole Buffer module in the bundle.
Since the http adapter is never used in the browser it's safe to use the Buffer global and its isBuffer() method directly.
An alternative to the function isBuffer (obj) {
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fgnass: In lib/adapters/http.js
you have removed Buffer, but you are still using it in the same file. Since Buffer is a global anyway, it is still being used.
Why not move the import of is-buffer from utils.js to http.js itself, and change this line to
if (isBuffer(data)) {
Or if you want to retain the function isBuffer in utils, you can do what @albertogasparin suggested.
BTW @albertogasparin: what you suggested is exactly what the is-buffer module does 😄
I removed the |
... in http.js it's fine to use the native |
@csvbox I know, as it's a one liner it looks silly to me importing a 3rd party dependency |
Does it matter for the webpack build? In webpack.config.js I don't see separate targets defined for |
@csvbox Webpack respects the |
My bad, |
@fgnass sorry I didn't see that before, thanks |
I would opt for keeping |
We're usually avoiding adding new dependencies to the project but since the module is very small I think it's OK. @mzabriskie, @nickuraltsev WDYT? |
I'm ok with this dependency. @fgnass Thank you for the PR! |
This Pull Request updates dependency [axios](https://github.com/axios/axios) from `v0.15.2` to `v0.18.0` <details> <summary>Release Notes</summary> ### [`v0.18.0`](https://github.com/axios/axios/blob/master/CHANGELOG.md#​0180-Feb-19-2018) [Compare Source](axios/axios@v0.17.1...v0.18.0) - Adding support for UNIX Sockets when running with Node.js ([#​1070](`https://github.com/axios/axios/pull/1070`)) - Fixing typings ([#​1177](`https://github.com/axios/axios/pull/1177`)): - AxiosRequestConfig.proxy: allows type false - AxiosProxyConfig: added auth field - Adding function signature in AxiosInstance interface so AxiosInstance can be invoked ([#​1192](`https://github.com/axios/axios/pull/1192`), [#​1254](`https://github.com/axios/axios/pull/1254`)) - Allowing maxContentLength to pass through to redirected calls as maxBodyLength in follow-redirects config ([#​1287](`https://github.com/axios/axios/pull/1287`)) - Fixing configuration when using an instance - method can now be set ([#​1342](`https://github.com/axios/axios/pull/1342`)) --- ### [`v0.17.1`](https://github.com/axios/axios/blob/master/CHANGELOG.md#​0171-Nov-11-2017) [Compare Source](axios/axios@v0.17.0...v0.17.1) - Fixing issue with web workers ([#​1160](`https://github.com/axios/axios/pull/1160`)) - Allowing overriding transport ([#​1080](`https://github.com/axios/axios/pull/1080`)) - Updating TypeScript typings ([#​1165](`https://github.com/axios/axios/pull/1165`), [#​1125](`https://github.com/axios/axios/pull/1125`), [#​1131](`https://github.com/axios/axios/pull/1131`)) --- ### [`v0.17.0`](https://github.com/axios/axios/blob/master/CHANGELOG.md#​0170-Oct-21-2017) [Compare Source](axios/axios@v0.16.2...v0.17.0) - **BREAKING** Fixing issue with `baseURL` and interceptors ([#​950](`https://github.com/axios/axios/pull/950`)) - **BREAKING** Improving handing of duplicate headers ([#​874](`https://github.com/axios/axios/pull/874`)) - Adding support for disabling proxies ([#​691](`https://github.com/axios/axios/pull/691`)) - Updating TypeScript typings with generic type parameters ([#​1061](`https://github.com/axios/axios/pull/1061`)) --- ### [`v0.16.2`](https://github.com/axios/axios/blob/master/CHANGELOG.md#​0162-Jun-3-2017) [Compare Source](axios/axios@v0.16.1...v0.16.2) - Fixing issue with including `buffer` in bundle ([#​887](`https://github.com/axios/axios/pull/887`)) - Including underlying request in errors ([#​830](`https://github.com/axios/axios/pull/830`)) - Convert `method` to lowercase ([#​930](`https://github.com/axios/axios/pull/930`)) --- ### [`v0.16.1`](https://github.com/axios/axios/blob/master/CHANGELOG.md#​0161-Apr-8-2017) [Compare Source](axios/axios@v0.16.0...v0.16.1) - Improving HTTP adapter to return last request in case of redirects ([#​828](`https://github.com/axios/axios/pull/828`)) - Updating `follow-redirects` dependency ([#​829](`https://github.com/axios/axios/pull/829`)) - Adding support for passing `Buffer` in node ([#​773](`https://github.com/axios/axios/pull/773`)) --- ### [`v0.16.0`](https://github.com/axios/axios/blob/master/CHANGELOG.md#​0160-Mar-31-2017) [Compare Source](axios/axios@v0.15.3...v0.16.0) - **BREAKING** Removing `Promise` from axios typings in favor of built-in type declarations ([#​480](`https://github.com/axios/axios/issues/480`)) - Adding `options` shortcut method ([#​461](`https://github.com/axios/axios/pull/461`)) - Fixing issue with using `responseType: 'json'` in browsers incompatible with XHR Level 2 ([#​654](`https://github.com/axios/axios/pull/654`)) - Improving React Native detection ([#​731](`https://github.com/axios/axios/pull/731`)) - Fixing `combineURLs` to support empty `relativeURL` ([#​581](`https://github.com/axios/axios/pull/581`)) - Removing `PROTECTION_PREFIX` support ([#​561](`https://github.com/axios/axios/pull/561`)) --- ### [`v0.15.3`](https://github.com/axios/axios/blob/master/CHANGELOG.md#​0153-Nov-27-2016) [Compare Source](axios/axios@v0.15.2...v0.15.3) - Fixing issue with custom instances and global defaults ([#​443](`https://github.com/axios/axios/issues/443`)) - Renaming `axios.d.ts` to `index.d.ts` ([#​519](`https://github.com/axios/axios/issues/519`)) - Adding `get`, `head`, and `delete` to `defaults.headers` ([#​509](`https://github.com/axios/axios/issues/509`)) - Fixing issue with `btoa` and IE ([#​507](`https://github.com/axios/axios/issues/507`)) - Adding support for proxy authentication ([#​483](`https://github.com/axios/axios/pull/483`)) - Improving HTTP adapter to use `http` protocol by default ([#​493](`https://github.com/axios/axios/pull/493`)) - Fixing proxy issues ([#​491](`https://github.com/axios/axios/pull/491`)) --- </details> --- This PR has been generated by [Renovate Bot](https://renovatebot.com).
This PR fixes #846 by using Feross' is-buffer module instead
Buffer.isBuffer()
.