Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed Apr 24, 2018
1 parent 922b986 commit 875e11c
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,24 @@ function simpleGet (opts, cb) {
cb = once(cb)

opts.headers = Object.assign({}, opts.headers)
parseHeaders(opts.headers)

if (opts.url) parseOptsUrl(opts)
Object.keys(opts.headers).forEach(function (h) {
if (h.toLowerCase() !== h) {
opts.headers[h.toLowerCase()] = opts.headers[h]
delete opts.headers[h]
}
})

if (opts.url) {
var loc = url.parse(opts.url)
if (loc.hostname) opts.hostname = loc.hostname
if (loc.port) opts.port = loc.port
if (loc.protocol) opts.protocol = loc.protocol
if (loc.auth) opts.auth = loc.auth
opts.path = loc.path
delete opts.url
}

if (opts.maxRedirects == null) opts.maxRedirects = 10
if (opts.method) opts.method = opts.method.toUpperCase()

Expand Down Expand Up @@ -95,23 +110,4 @@ simpleGet.concat = function (opts, cb) {
}
})

function parseHeaders (headers) {
Object.keys(headers).forEach(function (h) {
if (h.toLowerCase() !== h) {
headers[h.toLowerCase()] = headers[h]
delete headers[h]
}
})
}

function parseOptsUrl (opts) {
var loc = url.parse(opts.url)
if (loc.hostname) opts.hostname = loc.hostname
if (loc.port) opts.port = loc.port
if (loc.protocol) opts.protocol = loc.protocol
if (loc.auth) opts.auth = loc.auth
opts.path = loc.path
delete opts.url
}

function isStream (obj) { return typeof obj.pipe === 'function' }

0 comments on commit 875e11c

Please sign in to comment.