Skip to content

Commit

Permalink
Merge pull request #14 from fastly/jkarneges/allow-body
Browse files Browse the repository at this point in the history
Allow request bodies now that Fanout supports them
  • Loading branch information
jkarneges authored May 10, 2024
2 parents 8e7f924 + 5acd23c commit b2557a4
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
use fastly::{Body, Error, Request};

fn take_non_empty_body(req: &mut Request) -> Result<Option<Body>, Error> {
let mut chunks = req.get_body_mut().read_chunks(16_384);

let chunk = match chunks.next() {
Some(chunk) => chunk,
None => return Ok(None),
};

let mut body: Vec<u8> = Vec::new();
body.extend(chunk?);

for chunk in chunks {
body.extend(chunk?);
}

Ok(Some(Body::from(body)))
}
use fastly::{Error, Request};

fn main() -> Result<(), Error> {
// Log service version.
Expand All @@ -25,14 +7,7 @@ fn main() -> Result<(), Error> {
std::env::var("FASTLY_SERVICE_VERSION").unwrap_or_else(|_| String::new())
);

let mut req = Request::from_client();

if let Some(body) = take_non_empty_body(&mut req)? {
// Currently, Fanout only supports requests with empty bodies.
// If the request has a body, forward it to the backend directly.

return Ok(req.with_body(body).send("origin")?.send_to_client());
}
let req = Request::from_client();

Ok(req.handoff_fanout("origin")?)
}

0 comments on commit b2557a4

Please sign in to comment.