Skip to content

Commit

Permalink
Merge branch 'd1-support' of github.com:FlareLine/workers-rs into d1-…
Browse files Browse the repository at this point in the history
…support
  • Loading branch information
FlareLine committed May 5, 2023
2 parents 2154df8 + c35d762 commit f018e12
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result<Respo

The project uses [wrangler](https://github.com/cloudflare/wrangler2) version 2.x for running and publishing your Worker.

Get the Rust worker project [template](https://github.com/cloudflare/workers-sdk/tree/main/templates/worker-rust) manually, or run the following command:
Get the Rust worker project [template](https://github.com/cloudflare/workers-sdk/tree/main/templates/experimental/worker-rust) manually, or run the following command:
```bash
npm init cloudflare project_name worker-rust
cd project_name
Expand Down
2 changes: 1 addition & 1 deletion worker-sandbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ http = "0.2.8"
regex = "1.5.6"
serde = { version = "1.0.137", features = ["derive"] }
serde_json = "1.0.81"
worker = { path = "../worker", version = "0.0.14", features= ["d1", "queue"] }
worker = { path = "../worker", version = "0.0.15", features= ["d1", "queue"] }
futures-channel = "0.3.21"
futures-util = { version = "0.3.21", default-features = false }
rand = "0.8.5"
Expand Down
2 changes: 1 addition & 1 deletion worker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "worker"
version = "0.0.14"
version = "0.0.15"
authors = ["Cloudflare Workers Team <[email protected]>"]
repository = "https://github.com/cloudflare/workers-rs"
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use wasm_bindgen;
pub use wasm_bindgen_futures;
pub use worker_kv as kv;

pub use cf::Cf;
pub use cf::{Cf, TlsClientAuth};
pub use worker_macros::{durable_object, event};
#[doc(hidden)]
pub use worker_sys;
Expand Down
48 changes: 28 additions & 20 deletions worker/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,20 @@ impl From<ResponseInit> for web_sys::ResponseInit {
impl From<Response> for web_sys::Response {
fn from(res: Response) -> Self {
match res.body {
ResponseBody::Body(mut bytes) => web_sys::Response::new_with_opt_u8_array_and_init(
Some(&mut bytes),
&ResponseInit {
status: res.status_code,
headers: res.headers,
websocket: res.websocket,
}
.into(),
)
.unwrap(),
ResponseBody::Body(bytes) => {
let array = Uint8Array::new_with_length(bytes.len() as u32);
array.copy_from(&bytes);
web_sys::Response::new_with_opt_buffer_source_and_init(
Some(&array),
&ResponseInit {
status: res.status_code,
headers: res.headers,
websocket: res.websocket,
}
.into(),
)
.unwrap()
}
ResponseBody::Stream(stream) => {
web_sys::Response::new_with_opt_readable_stream_and_init(
Some(&stream),
Expand Down Expand Up @@ -393,16 +397,20 @@ impl From<Response> for web_sys::Response {
impl From<&Response> for web_sys::Response {
fn from(res: &Response) -> Self {
match &res.body {
ResponseBody::Body(bytes) => web_sys::Response::new_with_opt_u8_array_and_init(
Some(&mut bytes.clone()),
&ResponseInit {
status: res.status_code,
headers: res.headers.clone(),
websocket: res.websocket.clone(),
}
.into(),
)
.unwrap(),
ResponseBody::Body(bytes) => {
let array = Uint8Array::new_with_length(bytes.len() as u32);
array.copy_from(bytes);
web_sys::Response::new_with_opt_buffer_source_and_init(
Some(&array),
&ResponseInit {
status: res.status_code,
headers: res.headers.clone(),
websocket: res.websocket.clone(),
}
.into(),
)
.unwrap()
}
ResponseBody::Stream(stream) => {
web_sys::Response::new_with_opt_readable_stream_and_init(
Some(stream),
Expand Down

0 comments on commit f018e12

Please sign in to comment.