source: trip-planner-front/node_modules/make-fetch-happen/lib/options.js@ 6a80231

Last change on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1const conditionalHeaders = [
2 'if-modified-since',
3 'if-none-match',
4 'if-unmodified-since',
5 'if-match',
6 'if-range',
7]
8
9const configureOptions = (opts) => {
10 const {strictSSL, ...options} = { ...opts }
11 options.method = options.method ? options.method.toUpperCase() : 'GET'
12 options.rejectUnauthorized = strictSSL !== false
13
14 if (!options.retry)
15 options.retry = { retries: 0 }
16 else if (typeof options.retry === 'string') {
17 const retries = parseInt(options.retry, 10)
18 if (isFinite(retries))
19 options.retry = { retries }
20 else
21 options.retry = { retries: 0 }
22 } else if (typeof options.retry === 'number')
23 options.retry = { retries: options.retry }
24 else
25 options.retry = { retries: 0, ...options.retry }
26
27 options.cache = options.cache || 'default'
28 if (options.cache === 'default') {
29 const hasConditionalHeader = Object.keys(options.headers || {}).some((name) => {
30 return conditionalHeaders.includes(name.toLowerCase())
31 })
32 if (hasConditionalHeader)
33 options.cache = 'no-store'
34 }
35
36 // cacheManager is deprecated, but if it's set and
37 // cachePath is not we should copy it to the new field
38 if (options.cacheManager && !options.cachePath)
39 options.cachePath = options.cacheManager
40
41 return options
42}
43
44module.exports = configureOptions
Note: See TracBrowser for help on using the repository browser.