Skip to content

Commit

Permalink
0.2.0-alpha4 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Katelyn Martin committed Apr 8, 2020
1 parent 972421b commit 34897de
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 11 deletions.
75 changes: 69 additions & 6 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ edition = "2018"
debug = true

[dependencies]
fastly = "^0.2.0-alpha3"
fastly = "^0.2.0-alpha4"
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use fastly::http::{HeaderValue, Method, StatusCode};
use fastly::request::CacheOverride;
use fastly::{downstream_request, Body, Error, Request, RequestExt, Response, ResponseExt};
use std::convert::TryFrom;

const ONE_MINUTE_TTL: i32 = 60;
const NO_CACHE_TTL: i32 = -1;
const VALID_METHODS: [Method; 3] = [Method::HEAD, Method::GET, Method::POST];

/// Handle the downstream request from the client.
Expand Down Expand Up @@ -35,13 +34,15 @@ fn handle_request(mut req: Request<Body>) -> Result<Response<Body>, Error> {
// Request handling logic could go here...
// Eg. send the request to an origin backend and then cache the
// response for one minute.
req.send("backend_name", ONE_MINUTE_TTL)
req.set_cache_override(CacheOverride::ttl(60));
req.send("backend_name")
}

// If request is a `GET` to a path starting with `/other/`.
(&Method::GET, path) if path.starts_with("/other/") => {
// Send request to a different backend and don't cache response.
req.send("other_backend_name", NO_CACHE_TTL)
req.set_cache_override(CacheOverride::Pass);
req.send("other_backend_name")
}

// Catch all other requests and return a 404.
Expand Down

0 comments on commit 34897de

Please sign in to comment.