Skip to content

Commit 357f01d

Browse files
committed
fix: curly.post and curly.head using wrong libcurl options to set the HTTP method
1 parent acfa47a commit 357f01d

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
### Breaking Change
99
### Fixed
10+
- Fix `curly.post` and `curly.head` using wrong libcurl options to set the HTTP Method.
1011
### Added
1112
### Changed
1213

lib/curly.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,36 @@ const create = (): CurlyFunction => {
154154

155155
curly.create = create
156156

157+
const httpMethodOptionsMap: Record<
158+
string,
159+
null | ((m: string, o: CurlOptionValueType) => CurlOptionValueType)
160+
> = {
161+
get: null,
162+
post: (_m, o) => ({
163+
post: true,
164+
...o,
165+
}),
166+
head: (_m, o) => ({
167+
nobody: true,
168+
...o,
169+
}),
170+
_: (m, o) => ({
171+
customRequest: m,
172+
...o,
173+
}),
174+
}
175+
157176
for (const httpMethod of methods) {
177+
const httpMethodOptions =
178+
httpMethodOptionsMap[httpMethod] || httpMethodOptionsMap['_']
179+
158180
// @ts-ignore
159181
curly[httpMethod] =
160-
httpMethod === 'get'
182+
httpMethodOptions === null
161183
? curly
162184
: (url: string, options: CurlOptionValueType = {}) =>
163185
curly(url, {
164-
customRequest: httpMethod,
165-
...options,
186+
...httpMethodOptions(httpMethod, options),
166187
})
167188
}
168189

0 commit comments

Comments
 (0)