Skip to content

Commit d8c60e5

Browse files
committed
feat: request option
1 parent 33f5c1b commit d8c60e5

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

lib/request.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,19 @@ const getBuffer = require('./get-buffer-response')
88
const HttpError = require('./http-error')
99

1010
function request (fetch, requestOptions) {
11-
// https://fetch.spec.whatwg.org/#methods
12-
requestOptions.method = requestOptions.method.toUpperCase()
13-
14-
// default content-type for JSON
15-
if (requestOptions.body && !requestOptions.headers['content-type']) {
16-
requestOptions.headers['content-type'] = 'application/json; charset=utf-8'
17-
}
18-
19-
// GitHub expects "content-length: 0" header for PUT/PATCH requests without body
20-
// fetch does not allow to set `content-length` header, but we can set body to an empty string
21-
if (['PATCH', 'PUT'].indexOf(requestOptions.method) >= 0 && !requestOptions.body) {
22-
requestOptions.body = ''
23-
}
24-
2511
if (isPlainObject(requestOptions.body) || Array.isArray(requestOptions.body)) {
2612
requestOptions.body = JSON.stringify(requestOptions.body)
2713
}
2814

2915
let headers = {}
3016
let status
3117

32-
return fetch(requestOptions.url, {
18+
return fetch(requestOptions.url, Object.assign({
3319
method: requestOptions.method,
3420
body: requestOptions.body,
3521
headers: requestOptions.headers,
36-
redirect: requestOptions.redirect,
37-
timeout: requestOptions.timeout,
38-
agent: requestOptions.agent
39-
})
22+
redirect: requestOptions.redirect
23+
}, requestOptions.request))
4024

4125
.then(response => {
4226
status = response.status

0 commit comments

Comments
 (0)