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

Use non-persistent session for requests by default #12694

Merged
merged 1 commit into from
Jan 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions js/lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ const session = electron.session
const underscore = require('underscore')
const urlParse = require('../../app/common/urlParse')

var cachedDefaultSession = null

const getDefaultSession = () => {
if (!cachedDefaultSession) {
cachedDefaultSession = session.fromPartition('default')
}
return cachedDefaultSession
}

/**
* Sends a network request using Chromium's networks stack instead of Node's.
* Depends on there being a loaded browser window available.
Expand All @@ -17,8 +26,8 @@ const urlParse = require('../../app/common/urlParse')
*/
module.exports.request = (options, callback) => {
var params
var defaultSession = session.defaultSession
var responseType = options.responseType || 'text'
var defaultSession = getDefaultSession()

if (!defaultSession) return callback(new Error('Request failed, no session available'))

Expand Down Expand Up @@ -56,7 +65,7 @@ module.exports.request = (options, callback) => {
}

module.exports.requestDataFile = (url, headers, path, reject, resolve) => {
let defaultSession = session.defaultSession
var defaultSession = getDefaultSession()
if (!defaultSession) {
reject('Request failed, no session available')
} else {
Expand Down