The service's request and response as plain values: no HTTP library's types, so the same layer
serves a native server, a Worker's fetch handler and a test.
The largest request body served. A picture arrives as base64 inside the body: a few at 1024
pixels is a few hundred kilobytes. The adapter reads at most MAX_BODY + 1 bytes; a body that long
is refused.
11pub const MAX_BODY: usize = 8 * 1024 * 1024;
What the adapter managed to read of the request body.
The body could not be read (a device that dropped off wifi halfway, or not text).
28#[derive(Clone, Debug, PartialEq, Eq)] 29pub struct Request { 30 pub method: Method, 31 pub path: String, 32 pub body: Body, 33} 34 35impl Request { 36 pub fn post(path: &str, body: impl Into<String>) -> Self { 37 Self { method: Method::Post, path: path.to_owned(), body: Body::Text(body.into()) } 38 } 39}
What a response carries, which the adapter turns into its server's header.
No body and no content type.
45 None,
application/json.
47 Json,
Plain text, UTF-8 (text/plain; charset=UTF-8).
49 Text,
54#[derive(Clone, Debug, PartialEq, Eq)] 55pub struct Response { 56 pub status: u16, 57 pub content: Content, 58 pub body: Vec<u8>, 59} 60 61impl Response { 62 pub fn empty(status: u16) -> Self { 63 Self { status, content: Content::None, body: Vec::new() } 64 } 65 66 pub fn json(status: u16, body: String) -> Self { 67 Self { status, content: Content::Json, body: body.into_bytes() } 68 } 69 70 pub fn text(status: u16, body: String) -> Self { 71 Self { status, content: Content::Text, body: body.into_bytes() } 72 } 73 74 pub fn bytes(status: u16, content: Content, body: Vec<u8>) -> Self { 75 Self { status, content, body } 76 }
value as a 200 JSON reply. (A reply type of ours that cannot be serialised is a bug, answered
as a 500 and logged, never a panic in a request.)