Skip to content

Commit cc05d20

Browse files
authored
Adding support for http report method (#741)
1 parent a16090a commit cc05d20

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

worker-sandbox/tests/request.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ test("fetch json", async () => {
108108

109109
test("proxy request", async () => {
110110
const resp = await mf.dispatchFetch(
111-
"https://fake.host/proxy_request/https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding/contributors.txt"
111+
"https://fake.host/proxy_request/https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Encoding/contributors.txt"
112112
);
113113
expect(resp.status).toBe(200);
114114
});

worker/src/http.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub enum Method {
2525
Options,
2626
Connect,
2727
Trace,
28+
Report,
2829
}
2930

3031
impl Method {
@@ -39,6 +40,7 @@ impl Method {
3940
Method::Options,
4041
Method::Connect,
4142
Method::Trace,
43+
Method::Report,
4244
]
4345
}
4446
}
@@ -54,6 +56,7 @@ impl From<String> for Method {
5456
"OPTIONS" => Method::Options,
5557
"CONNECT" => Method::Connect,
5658
"TRACE" => Method::Trace,
59+
"REPORT" => Method::Report,
5760
_ => Method::Get,
5861
}
5962
}
@@ -77,6 +80,7 @@ impl AsRef<str> for Method {
7780
Method::Connect => "CONNECT",
7881
Method::Trace => "TRACE",
7982
Method::Get => "GET",
83+
Method::Report => "REPORT",
8084
}
8185
}
8286
}

worker/src/router.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ impl<'a, D: 'a> Router<'a, D> {
173173
self
174174
}
175175

176+
/// Register an HTTP handler that will exclusively respond to REPORT requests.
177+
pub fn report(mut self, pattern: &str, func: HandlerFn<D>) -> Self {
178+
self.add_handler(pattern, Handler::Sync(func), vec![Method::Report]);
179+
self
180+
}
181+
176182
/// Register an HTTP handler that will respond to any requests.
177183
pub fn on(mut self, pattern: &str, func: HandlerFn<D>) -> Self {
178184
self.add_handler(pattern, Handler::Sync(func), Method::all());

worker/src/socket.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::{
22
convert::TryFrom,
3-
io::ErrorKind,
43
pin::Pin,
54
task::{Context, Poll},
65
};
@@ -150,7 +149,7 @@ fn js_value_to_std_io_error(value: JsValue) -> IoError {
150149
} else {
151150
format!("Error interpreting JsError: {:?}", value)
152151
};
153-
IoError::new(ErrorKind::Other, s)
152+
IoError::other(s)
154153
}
155154
impl AsyncRead for Socket {
156155
fn poll_read(
@@ -173,10 +172,7 @@ impl AsyncRead for Socket {
173172
Ok(value) => value.into(),
174173
Err(error) => {
175174
let msg = format!("Unable to interpret field 'done' in ReadableStreamDefaultReader.read(): {:?}", error);
176-
return (
177-
Reading::None,
178-
Poll::Ready(Err(IoError::new(ErrorKind::Other, msg))),
179-
);
175+
return (Reading::None, Poll::Ready(Err(IoError::other(msg))));
180176
}
181177
};
182178
if done.is_truthy() {
@@ -189,10 +185,7 @@ impl AsyncRead for Socket {
189185
Ok(value) => value.into(),
190186
Err(error) => {
191187
let msg = format!("Unable to interpret field 'value' in ReadableStreamDefaultReader.read(): {:?}", error);
192-
return (
193-
Reading::None,
194-
Poll::Ready(Err(IoError::new(ErrorKind::Other, msg))),
195-
);
188+
return (Reading::None, Poll::Ready(Err(IoError::other(msg))));
196189
}
197190
};
198191
let data = arr.to_vec();
@@ -214,7 +207,7 @@ impl AsyncRead for Socket {
214207
"Unable to cast JsObject to ReadableStreamDefaultReader: {:?}",
215208
error
216209
);
217-
return Poll::Ready(Err(IoError::new(ErrorKind::Other, msg)));
210+
return Poll::Ready(Err(IoError::other(msg)));
218211
}
219212
};
220213

@@ -241,7 +234,7 @@ impl AsyncWrite for Socket {
241234
Ok(writer) => writer,
242235
Err(error) => {
243236
let msg = format!("Could not retrieve Writer: {:?}", error);
244-
return Poll::Ready(Err(IoError::new(ErrorKind::Other, msg)));
237+
return Poll::Ready(Err(IoError::other(msg)));
245238
}
246239
};
247240
Self::handle_write_future(

0 commit comments

Comments
 (0)