Skip to content

Commit

Permalink
feat: request option
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Oct 24, 2018
1 parent 0b4a7b1 commit 26f3548
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/endpoint-with-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function endpointWithDefaults (defaults, route, options) {
options = route
}

// lowercase header names
// lowercase header names before merging with defaults to avoid duplicates
if (options.headers) {
options.headers = Object.keys(options.headers).reduce((newObj, key) => {
newObj[key.toLowerCase()] = options.headers[key]
Expand All @@ -24,12 +24,11 @@ function endpointWithDefaults (defaults, route, options) {

options = merge.all([defaults, options].filter(Boolean))

let body = options.body
let method = options.method.toLowerCase()
let baseUrl = options.baseUrl
let url = options.url
let headers = options.headers
let remainingOptions = omit(options, ['method', 'baseUrl', 'url', 'headers'])
let body
let remainingOptions = omit(options, ['method', 'baseUrl', 'url', 'headers', 'request'])

// replace :varname with {varname} to make it RFC 6570 compatible
url = url.replace(/:([a-z]\w+)/g, '{+$1}')
Expand All @@ -40,7 +39,7 @@ function endpointWithDefaults (defaults, route, options) {
url = urlTemplate.parse(url).expand(remainingOptions)

if (!/^http/.test(url)) {
url = baseUrl + url
url = options.baseUrl + url
}

const omittedOptions = Object.keys(options).filter((option) => urlVariableNames.includes(option)).concat('baseUrl')
Expand Down Expand Up @@ -71,6 +70,10 @@ function endpointWithDefaults (defaults, route, options) {
requestOptions.body = body
}

if (options.request) {
requestOptions.request = options.request
}

return requestOptions
}

Expand Down

0 comments on commit 26f3548

Please sign in to comment.