Skip to content

Commit c6b0588

Browse files
Mantisusbarjin
andauthored
fix: allow passing request body in all HTTP methods except TRACE (#238)
Co-authored-by: Jindřich Bär <jindrichbar@gmail.com>
1 parent ec48c8d commit c6b0588

5 files changed

Lines changed: 24 additions & 20 deletions

File tree

impit-cli/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ async fn main() {
128128
};
129129

130130
let response = match args.method {
131-
Method::Get => client.get(args.url, Some(options)).await.unwrap(),
131+
Method::Get => client.get(args.url, body, Some(options)).await.unwrap(),
132132
Method::Post => client.post(args.url, body, Some(options)).await.unwrap(),
133133
Method::Put => client.put(args.url, body, Some(options)).await.unwrap(),
134-
Method::Delete => client.delete(args.url, Some(options)).await.unwrap(),
134+
Method::Delete => client.delete(args.url, body, Some(options)).await.unwrap(),
135135
Method::Patch => client.patch(args.url, body, Some(options)).await.unwrap(),
136-
Method::Head => client.head(args.url, Some(options)).await.unwrap(),
137-
Method::Options => client.options(args.url, Some(options)).await.unwrap(),
136+
Method::Head => client.head(args.url, body, Some(options)).await.unwrap(),
137+
Method::Options => client.options(args.url, body, Some(options)).await.unwrap(),
138138
Method::Trace => client.trace(args.url, Some(options)).await.unwrap(),
139139
};
140140

impit-node/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ impl ImpitWrapper {
7676
} else {
7777
// Match the HTTP method and execute the corresponding request
7878
match method {
79-
HttpMethod::Get => self.inner.get(url, request_options).await,
80-
HttpMethod::Head => self.inner.head(url, request_options).await,
79+
HttpMethod::Get => self.inner.get(url, body, request_options).await,
80+
HttpMethod::Head => self.inner.head(url, body, request_options).await,
8181
HttpMethod::Post => self.inner.post(url, body, request_options).await,
8282
HttpMethod::Put => self.inner.put(url, body, request_options).await,
83-
HttpMethod::Delete => self.inner.delete(url, request_options).await,
83+
HttpMethod::Delete => self.inner.delete(url, body, request_options).await,
8484
HttpMethod::Patch => self.inner.patch(url, body, request_options).await,
85-
HttpMethod::Options => self.inner.options(url, request_options).await,
85+
HttpMethod::Options => self.inner.options(url, body, request_options).await,
8686
}
8787
};
8888

impit-python/src/async_client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,14 @@ impl AsyncClient {
416416

417417
pyo3_async_runtimes::tokio::future_into_py::<_, ImpitPyResponse>(py, async move {
418418
let response = match method_str.to_lowercase().as_str() {
419-
"get" => impit.get(url, Some(options)).await,
419+
"get" => impit.get(url, Some(body), Some(options)).await,
420420
"post" => impit.post(url, Some(body), Some(options)).await,
421421
"patch" => impit.patch(url, Some(body), Some(options)).await,
422422
"put" => impit.put(url, Some(body), Some(options)).await,
423-
"options" => impit.options(url, Some(options)).await,
423+
"options" => impit.options(url, Some(body), Some(options)).await,
424424
"trace" => impit.trace(url, Some(options)).await,
425-
"head" => impit.head(url, Some(options)).await,
426-
"delete" => impit.delete(url, Some(options)).await,
425+
"head" => impit.head(url, Some(body), Some(options)).await,
426+
"delete" => impit.delete(url, Some(body), Some(options)).await,
427427
_ => Err(ImpitError::InvalidMethod(method_str.to_string())),
428428
};
429429

impit-python/src/client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,14 @@ impl Client {
401401
py.allow_threads(|| {
402402
pyo3_async_runtimes::tokio::get_runtime().block_on(async {
403403
let response = match method.to_lowercase().as_str() {
404-
"get" => self.impit.get(url, Some(options)).await,
404+
"get" => self.impit.get(url, Some(body), Some(options)).await,
405405
"post" => self.impit.post(url, Some(body), Some(options)).await,
406406
"patch" => self.impit.patch(url, Some(body), Some(options)).await,
407407
"put" => self.impit.put(url, Some(body), Some(options)).await,
408-
"options" => self.impit.options(url, Some(options)).await,
408+
"options" => self.impit.options(url, Some(body), Some(options)).await,
409409
"trace" => self.impit.trace(url, Some(options)).await,
410-
"head" => self.impit.head(url, Some(options)).await,
411-
"delete" => self.impit.delete(url, Some(options)).await,
410+
"head" => self.impit.head(url, Some(body), Some(options)).await,
411+
"delete" => self.impit.delete(url, Some(body), Some(options)).await,
412412
_ => Err(ImpitError::InvalidMethod(method.to_string())),
413413
};
414414

impit/src/impit.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,10 @@ impl<CookieStoreImpl: CookieStore + 'static> Impit<CookieStoreImpl> {
410410
pub async fn get(
411411
&self,
412412
url: String,
413+
body: Option<Vec<u8>>,
413414
options: Option<RequestOptions>,
414415
) -> Result<Response, ImpitError> {
415-
self.make_request(Method::GET, url, None, options).await
416+
self.make_request(Method::GET, url, body, options).await
416417
}
417418

418419
/// Makes a `HEAD` request to the specified URL.
@@ -424,9 +425,10 @@ impl<CookieStoreImpl: CookieStore + 'static> Impit<CookieStoreImpl> {
424425
pub async fn head(
425426
&self,
426427
url: String,
428+
body: Option<Vec<u8>>,
427429
options: Option<RequestOptions>,
428430
) -> Result<Response, ImpitError> {
429-
self.make_request(Method::HEAD, url, None, options).await
431+
self.make_request(Method::HEAD, url, body, options).await
430432
}
431433

432434
/// Makes an OPTIONS request to the specified URL.
@@ -438,9 +440,10 @@ impl<CookieStoreImpl: CookieStore + 'static> Impit<CookieStoreImpl> {
438440
pub async fn options(
439441
&self,
440442
url: String,
443+
body: Option<Vec<u8>>,
441444
options: Option<RequestOptions>,
442445
) -> Result<Response, ImpitError> {
443-
self.make_request(Method::OPTIONS, url, None, options).await
446+
self.make_request(Method::OPTIONS, url, body, options).await
444447
}
445448

446449
/// Makes a `TRACE` request to the specified URL.
@@ -466,9 +469,10 @@ impl<CookieStoreImpl: CookieStore + 'static> Impit<CookieStoreImpl> {
466469
pub async fn delete(
467470
&self,
468471
url: String,
472+
body: Option<Vec<u8>>,
469473
options: Option<RequestOptions>,
470474
) -> Result<Response, ImpitError> {
471-
self.make_request(Method::DELETE, url, None, options).await
475+
self.make_request(Method::DELETE, url, body, options).await
472476
}
473477

474478
/// Makes a `POST` request to the specified URL.

0 commit comments

Comments
 (0)