Skip to content

Commit 63c976e

Browse files
committed
fix: handle x-rewrite-url header
1 parent fbb5a7b commit 63c976e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/martin.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,23 @@ fn source(req: HttpRequest<State>) -> Result<HttpResponse> {
4343
.get("sources")
4444
.ok_or(error::ErrorBadRequest("invalid source"))?;
4545

46+
let path = req.headers()
47+
.get("x-rewrite-url")
48+
.map_or(String::from(source_ids), |header| {
49+
let parts: Vec<&str> = header.to_str().unwrap().split(".").collect();
50+
let (_, parts_without_extension) = parts.split_last().unwrap();
51+
let path_without_extension = parts_without_extension.join(".");
52+
let (_, path_without_leading_slash) = path_without_extension.split_at(1);
53+
54+
String::from(path_without_leading_slash)
55+
});
56+
57+
let conn = req.connection_info();
4658
let tiles_url = format!(
47-
"{}/{{z}}/{{x}}/{{y}}.pbf",
48-
req.url_for("tilejson", &[source_ids]).unwrap()
59+
"{}://{}/{}/{{z}}/{{x}}/{{y}}.pbf",
60+
conn.scheme(),
61+
conn.host(),
62+
path
4963
);
5064

5165
let mut tilejson_builder = TileJSONBuilder::new();

0 commit comments

Comments
 (0)