Skip to content

Commit

Permalink
Test getting the complete request URL
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Aug 8, 2024
1 parent 668252f commit 73b903b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ aws-sdk-s3 = "1.42.0"
aws-smithy-async = "1.2.1"
aws-smithy-runtime-api = "1.7.1"
aws-smithy-types-convert = { version = "0.60.8", features = ["convert-time"] }
axum = { version = "0.7.5", default-features = false, features = ["http1", "tokio", "tower-log"] }
axum = { version = "0.7.5", default-features = false, features = ["http1", "original-uri", "tokio", "tower-log"] }
bytes = "1.7.1"
clap = { version = "4.5.13", default-features = false, features = ["derive", "error-context", "help", "std", "suggestions", "usage", "wrap_help"] }
enum_dispatch = "0.3.13"
Expand Down
21 changes: 19 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::zarrman::ZarrManClient;
use anyhow::Context;
use axum::{
body::Body,
extract::Request,
extract::{Host, OriginalUri, Request},
http::{
header::{HeaderValue, ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_TYPE, SERVER},
header::{HeaderMap, HeaderValue, ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_TYPE, SERVER},
response::Response,
Method,
},
Expand All @@ -28,6 +28,7 @@ use axum::{
};
use clap::Parser;
use std::fmt;
use std::fmt::Write;
use std::io::{stderr, IsTerminal};
use std::net::IpAddr;
use std::sync::Arc;
Expand Down Expand Up @@ -113,6 +114,22 @@ async fn run() -> anyhow::Result<()> {
([(CONTENT_TYPE, CSS_CONTENT_TYPE)], STYLESHEET)
}),
)
.route(
"/.test",
get(
|host: Host, orig: OriginalUri, headers: HeaderMap, req: Request| async move {
let mut s = String::new();
writeln!(&mut s, "Host: {}", host.0).unwrap();
writeln!(&mut s, "Original URI: {}", orig.0).unwrap();
writeln!(&mut s, "Request URI: {}", req.uri()).unwrap();
writeln!(&mut s, "Headers:").unwrap();
for (name, value) in &headers {
writeln!(&mut s, " {name}: {value:?}").unwrap();
}
s
},
),
)

Check warning on line 132 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L117-L132

Added lines #L117 - L132 were not covered by tests
.nest_service(
"/",
service_fn(move |req: Request| {
Expand Down

0 comments on commit 73b903b

Please sign in to comment.