Skip to content

Commit

Permalink
Add ability to opt-out of using electron.net
Browse files Browse the repository at this point in the history
And support using it in the renderer process => #314
  • Loading branch information
sindresorhus committed May 26, 2017
1 parent 7964f2c commit 6fc1902
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ function requestAsEventEmitter(opts) {

let fn = opts.protocol === 'https:' ? https : http;

if (process.versions.electron) {
fn = require('electron').net;
if (opts.useElectronNet && process.versions.electron) {
const electron = require('electron');
fn = electron.net || electron.remote.net;
}

const req = fn.request(opts, res => {
Expand Down Expand Up @@ -278,7 +279,8 @@ function normalizeArguments(url, opts) {
opts = Object.assign(
{
path: '',
retries: 2
retries: 2,
useElectronNet: true
},
url,
{
Expand Down
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ Defines if redirect responses should be followed automatically.
Note that if a `303` is sent by the server in response to any request type (`POST`, `DELETE`, etc.), got will automatically
request the resource pointed to in the location header via `GET`. This is in accordance with [the spec](https://tools.ietf.org/html/rfc7231#section-6.4.4).

###### useElectronNet

Type: `boolean`<br>
Default: `true`

When used in Electron, Got will automatically use [`electron.net`](https://electron.atom.io/docs/api/net/) instead of the Node.js `http` module. It should be fully compatible, but you can turn it off here if you encounter a problem. Please open an issue if you do!


#### Streams

#### got.stream(url, [options])
Expand Down

0 comments on commit 6fc1902

Please sign in to comment.