-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix body null for null status * Post request * adding size * clippy,fmt * hasReqBody
- Loading branch information
1 parent
31180a0
commit c02987e
Showing
7 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts" | ||
|
||
serve(async (req: Request) => { | ||
return new Response(null, { status: 204 }) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use base::worker_ctx::{create_worker, WorkerRequestMsg}; | ||
use hyper::{Body, Request, Response}; | ||
use sb_worker_context::essentials::{EdgeContextInitOpts, EdgeContextOpts, EdgeUserRuntimeOpts}; | ||
use std::collections::HashMap; | ||
use tokio::sync::oneshot; | ||
|
||
#[tokio::test] | ||
async fn test_null_body_with_204_status() { | ||
let user_rt_opts = EdgeUserRuntimeOpts::default(); | ||
let opts = EdgeContextInitOpts { | ||
service_path: "./test_cases/empty-response".into(), | ||
no_module_cache: false, | ||
import_map_path: None, | ||
env_vars: HashMap::new(), | ||
conf: EdgeContextOpts::UserWorker(user_rt_opts), | ||
}; | ||
let worker_req_tx = create_worker(opts).await.unwrap(); | ||
let (res_tx, res_rx) = oneshot::channel::<Result<Response<Body>, hyper::Error>>(); | ||
|
||
let req = Request::builder() | ||
.uri("/") | ||
.method("GET") | ||
.body(Body::empty()) | ||
.unwrap(); | ||
|
||
let msg = WorkerRequestMsg { req, res_tx }; | ||
let _ = worker_req_tx.send(msg); | ||
|
||
let res = res_rx.await.unwrap().unwrap(); | ||
assert!(res.status().as_u16() == 204); | ||
|
||
let body_bytes = hyper::body::to_bytes(res.into_body()) | ||
.await | ||
.unwrap() | ||
.to_vec(); | ||
|
||
assert_eq!(body_bytes.len(), 0); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_null_body_with_204_status_post() { | ||
let user_rt_opts = EdgeUserRuntimeOpts::default(); | ||
let opts = EdgeContextInitOpts { | ||
service_path: "./test_cases/empty-response".into(), | ||
no_module_cache: false, | ||
import_map_path: None, | ||
env_vars: HashMap::new(), | ||
conf: EdgeContextOpts::UserWorker(user_rt_opts), | ||
}; | ||
let worker_req_tx = create_worker(opts).await.unwrap(); | ||
let (res_tx, res_rx) = oneshot::channel::<Result<Response<Body>, hyper::Error>>(); | ||
|
||
let req = Request::builder() | ||
.uri("/") | ||
.method("POST") | ||
.body(Body::empty()) | ||
.unwrap(); | ||
|
||
let msg = WorkerRequestMsg { req, res_tx }; | ||
let _ = worker_req_tx.send(msg); | ||
|
||
let res = res_rx.await.unwrap().unwrap(); | ||
assert!(res.status().as_u16() == 204); | ||
|
||
let body_bytes = hyper::body::to_bytes(res.into_body()) | ||
.await | ||
.unwrap() | ||
.to_vec(); | ||
|
||
assert_eq!(body_bytes.len(), 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts" | ||
|
||
serve(async (req: Request) => { | ||
return new Response(null, { status: 204 }) | ||
}); |