forked from ordinals/ord
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
27 changed files
with
650 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "audit-cache" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
colored = "2.0.4" | ||
reqwest = { version = "0.11.22", features = ["blocking"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use { | ||
colored::Colorize, | ||
reqwest::{blocking::get, StatusCode}, | ||
std::process, | ||
}; | ||
|
||
const ENDPOINTS: &[(&str, StatusCode, &str)] = &[ | ||
// PNG content is cached | ||
( | ||
"/content/6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0", | ||
StatusCode::OK, | ||
"HIT", | ||
), | ||
// HTML content is cached | ||
( | ||
"/content/114c5c87c4d0a7facb2b4bf515a4ad385182c076a5cfcc2982bf2df103ec0fffi0", | ||
StatusCode::OK, | ||
"HIT", | ||
), | ||
// content respopnses that aren't found aren't cached | ||
( | ||
"/content/6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i1", | ||
StatusCode::NOT_FOUND, | ||
"BYPASS", | ||
), | ||
// HTML previews are cached | ||
( | ||
"/preview/114c5c87c4d0a7facb2b4bf515a4ad385182c076a5cfcc2982bf2df103ec0fffi0", | ||
StatusCode::OK, | ||
"HIT", | ||
), | ||
// non-HTML previews are not cached | ||
( | ||
"/preview/6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0", | ||
StatusCode::OK, | ||
"BYPASS", | ||
), | ||
("/static/index.css", StatusCode::OK, "HIT"), | ||
("/static/index.js", StatusCode::OK, "HIT"), | ||
("/sat/FOO", StatusCode::BAD_REQUEST, "HIT"), | ||
("/", StatusCode::OK, "BYPASS"), | ||
("/blockheight", StatusCode::OK, "BYPASS"), | ||
]; | ||
|
||
fn main() { | ||
eprint!("Warming up the cache"); | ||
|
||
for (endpoint, expected_status_code, _expected_cache_status) in ENDPOINTS { | ||
let response = get(format!("https://ordinals.com{endpoint}")).unwrap(); | ||
|
||
assert_eq!(response.status(), *expected_status_code); | ||
|
||
eprint!("."); | ||
} | ||
|
||
eprintln!(); | ||
|
||
let mut failures = 0; | ||
|
||
for (endpoint, expected_status_code, expected_cache_status) in ENDPOINTS { | ||
eprint!("GET {endpoint}"); | ||
|
||
let response = get(format!("https://ordinals.com{endpoint}")).unwrap(); | ||
|
||
let status_code = response.status(); | ||
|
||
eprint!(" {}", status_code.as_u16()); | ||
|
||
assert_eq!(response.status(), *expected_status_code); | ||
|
||
let cache_status = response.headers().get("cf-cache-status").unwrap(); | ||
|
||
let pass = cache_status == expected_cache_status; | ||
|
||
if pass { | ||
eprintln!(" {}", cache_status.to_str().unwrap().green()); | ||
} else { | ||
eprintln!(" {}", cache_status.to_str().unwrap().red()); | ||
} | ||
|
||
failures += u32::from(!pass); | ||
} | ||
|
||
if failures > 0 { | ||
eprintln!("{failures} failures"); | ||
process::exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.