Fixing code review issues: adding a partition options and making the session option only takes Session objects.
This commit is contained in:
parent
6d7f179a9b
commit
b44d5290e2
4 changed files with 40 additions and 17 deletions
|
@ -5,6 +5,7 @@ const {EventEmitter} = require('events')
|
|||
const util = require('util')
|
||||
const {Readable} = require('stream')
|
||||
const {app} = require('electron')
|
||||
const {session} = require('electron')
|
||||
const {net, Net} = process.atomBinding('net')
|
||||
const {URLRequest} = net
|
||||
|
||||
|
@ -155,12 +156,25 @@ class ClientRequest extends EventEmitter {
|
|||
urlStr = url.format(urlObj)
|
||||
}
|
||||
|
||||
const sessionName = options.session || ''
|
||||
let urlRequest = new URLRequest({
|
||||
let urlRequestOptions = {
|
||||
method: method,
|
||||
url: urlStr,
|
||||
session: sessionName
|
||||
})
|
||||
url: urlStr
|
||||
}
|
||||
if (options.session) {
|
||||
if (options.session instanceof session.Session) {
|
||||
urlRequestOptions.session = options.session
|
||||
} else {
|
||||
throw new TypeError('`session` should be an instance of the Session class.')
|
||||
}
|
||||
} else if (options.partition) {
|
||||
if (typeof options.partition === 'string') {
|
||||
urlRequestOptions.partition = options.partition
|
||||
} else {
|
||||
throw new TypeError('`partition` should be an a string.')
|
||||
}
|
||||
}
|
||||
|
||||
let urlRequest = new URLRequest(urlRequestOptions)
|
||||
|
||||
// Set back and forward links.
|
||||
this.urlRequest = urlRequest
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue