Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3a36ec5
add etag handling to all non-critical endpoints
CommanderStorm May 19, 2025
9af57bd
run cargo fmt
CommanderStorm May 19, 2025
664e5a6
resort dependencys
CommanderStorm May 19, 2025
6303247
use imports instea of direct referencing
CommanderStorm May 19, 2025
f39bf8c
fix accidental whitespace change
CommanderStorm May 19, 2025
a711616
fix clippy lints
CommanderStorm May 19, 2025
1d7c304
Merge branch 'main' into more-etag-handling
nyurik May 20, 2025
1e5c1c8
Merge branch 'main' into more-etag-handling
CommanderStorm May 20, 2025
a357a8d
Merge branch 'main' into more-etag-handling
CommanderStorm May 21, 2025
74b4d8c
Merge remote-tracking branch 'maplibre/main' into pr/CommanderStorm/1836
sharkAndshark May 21, 2025
43bdd4e
fmt and clippy
sharkAndshark May 21, 2025
1cb751c
change the import as requested
CommanderStorm May 21, 2025
d934616
asserted that headers don't change
CommanderStorm May 21, 2025
267c5dd
asserted that headers don't change
CommanderStorm May 21, 2025
36d8127
apply sorting to the headers
CommanderStorm May 21, 2025
54728bd
reorder wraps to convey what we want
CommanderStorm May 21, 2025
98ade44
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 21, 2025
793c0fb
strip leading and trailing whitespace from header files
CommanderStorm May 21, 2025
1e9cd9e
re-bless outputs
CommanderStorm May 21, 2025
407af52
reset to the less smart awk command
CommanderStorm May 21, 2025
1904e9e
fix line ending diff
CommanderStorm May 21, 2025
d6b2177
remove etag handling for catalogs where the etags are not actually st…
CommanderStorm May 21, 2025
8cfd4a3
Merge branch 'main' into more-etag-handling
CommanderStorm May 21, 2025
a26a0dc
fix formatting
CommanderStorm May 21, 2025
7c2676b
Merge branch 'main' into more-etag-handling
nyurik May 21, 2025
9711cf7
move header dumping near header dumping
CommanderStorm May 25, 2025
7dff847
Merge branch 'main' into more-etag-handling
CommanderStorm May 25, 2025
86c5952
fix CI disagreeing if `pmt2_0_0_0.png.txt` has alpha
CommanderStorm May 25, 2025
5c2aa2d
remove testing file
CommanderStorm May 25, 2025
0afbbc8
Merge branch 'main' into more-etag-handling
CommanderStorm May 26, 2025
e18d4a5
add an expected file for auto/s3_1_0_0.pbf.headers
CommanderStorm May 26, 2025
bfe3baf
apply `just fmt` and some of the suggestions of `just clippy` (the on…
CommanderStorm May 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct_field_names = "allow"
[workspace.dependencies]
actix-cors = "0.7"
actix-http = "3"
actix-middleware-etag = "0.4.4"
actix-rt = "2"
actix-web = "4"
actix-web-static-files = "4"
Expand Down
1 change: 1 addition & 0 deletions martin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ bless-tests = []
[dependencies]
actix-cors.workspace = true
actix-http.workspace = true
actix-middleware-etag.workspace = true
actix-rt.workspace = true
actix-web-static-files = { workspace = true, optional = true }
actix-web.workspace = true
Expand Down
7 changes: 5 additions & 2 deletions martin/src/srv/fonts.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::string::ToString;

use actix_middleware_etag::Etag;
use actix_web::error::{ErrorBadRequest, ErrorNotFound};
use actix_web::middleware::Compress;
use actix_web::web::{Data, Path};
use actix_web::{HttpResponse, Result as ActixResult, middleware, route};
use actix_web::{HttpResponse, Result as ActixResult, route};
use serde::Deserialize;

use crate::fonts::{FontError, FontSources};
Expand All @@ -18,7 +20,8 @@ struct FontRequest {
#[route(
"/font/{fontstack}/{start}-{end}",
method = "GET",
wrap = "middleware::Compress::default()"
wrap = "Etag",
wrap = "Compress::default()"
)]
#[allow(clippy::unused_async)]
async fn get_font(path: Path<FontRequest>, fonts: Data<FontSources>) -> ActixResult<HttpResponse> {
Expand Down
10 changes: 5 additions & 5 deletions martin/src/srv/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use std::time::Duration;
use actix_cors::Cors;
use actix_web::error::ErrorInternalServerError;
use actix_web::http::header::CACHE_CONTROL;
use actix_web::middleware::TrailingSlash;
use actix_web::middleware::{Compress, Logger, NormalizePath, TrailingSlash};
use actix_web::web::Data;
use actix_web::{App, HttpResponse, HttpServer, Responder, middleware, route, web};
use actix_web::{App, HttpResponse, HttpServer, Responder, route, web};
use futures::TryFutureExt;
#[cfg(feature = "lambda")]
use lambda_web::{is_running_on_lambda, run_actix_on_lambda};
Expand Down Expand Up @@ -105,7 +105,7 @@ async fn get_health() -> impl Responder {
"/catalog",
method = "GET",
method = "HEAD",
wrap = "middleware::Compress::default()"
wrap = "Compress::default()"
)]
#[allow(clippy::unused_async)]
async fn get_catalog(catalog: Data<Catalog>) -> impl Responder {
Expand Down Expand Up @@ -182,8 +182,8 @@ pub fn new_server(config: SrvConfig, state: ServerState) -> MartinResult<(Server
app.app_data(Data::new(catalog.clone()))
.app_data(Data::new(config.clone()))
.wrap(cors_middleware)
.wrap(middleware::NormalizePath::new(TrailingSlash::MergeOnly))
.wrap(middleware::Logger::default())
.wrap(NormalizePath::new(TrailingSlash::MergeOnly))
.wrap(Logger::default())
.configure(|c| router(c, &config))
};

Expand Down
24 changes: 19 additions & 5 deletions martin/src/srv/sprites.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
use std::string::ToString;

use actix_middleware_etag::Etag;
use actix_web::error::ErrorNotFound;
use actix_web::http::header::ContentType;
use actix_web::middleware::Compress;
use actix_web::web::{Data, Path};
use actix_web::{HttpResponse, Result as ActixResult, middleware, route};
use actix_web::{HttpResponse, Result as ActixResult, route};
use spreet::Spritesheet;

use crate::sprites::{SpriteError, SpriteSources};
use crate::srv::SourceIDsRequest;
use crate::srv::server::map_internal_error;

#[route("/sprite/{source_ids}.png", method = "GET", method = "HEAD")]
#[route(
"/sprite/{source_ids}.png",
method = "GET",
method = "HEAD",
wrap = "Etag"
)]
async fn get_sprite_png(
path: Path<SourceIDsRequest>,
sprites: Data<SpriteSources>,
Expand All @@ -21,7 +28,12 @@ async fn get_sprite_png(
.body(sheet.encode_png().map_err(map_internal_error)?))
}

#[route("/sdf_sprite/{source_ids}.png", method = "GET", method = "HEAD")]
#[route(
"/sdf_sprite/{source_ids}.png",
method = "GET",
method = "HEAD",
wrap = "Etag"
)]
async fn get_sprite_sdf_png(
path: Path<SourceIDsRequest>,
sprites: Data<SpriteSources>,
Expand All @@ -36,7 +48,8 @@ async fn get_sprite_sdf_png(
"/sprite/{source_ids}.json",
method = "GET",
method = "HEAD",
wrap = "middleware::Compress::default()"
wrap = "Etag",
wrap = "Compress::default()"
)]
async fn get_sprite_json(
path: Path<SourceIDsRequest>,
Expand All @@ -50,7 +63,8 @@ async fn get_sprite_json(
"/sdf_sprite/{source_ids}.json",
method = "GET",
method = "HEAD",
wrap = "middleware::Compress::default()"
wrap = "Etag",
wrap = "Compress::default()"
)]
async fn get_sprite_sdf_json(
path: Path<SourceIDsRequest>,
Expand Down
7 changes: 5 additions & 2 deletions martin/src/srv/styles.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use actix_middleware_etag::Etag;
use actix_web::http::header::ContentType;
use actix_web::middleware::Compress;
use actix_web::web::{Data, Path};
use actix_web::{HttpResponse, middleware, route};
use actix_web::{HttpResponse, route};
use log::error;
use serde::Deserialize;

Expand All @@ -14,7 +16,8 @@ struct StyleRequest {
#[route(
"/style/{style_id}",
method = "GET",
wrap = "middleware::Compress::default()"
wrap = "Etag",
wrap = "Compress::default()"
)]
async fn get_style_json(path: Path<StyleRequest>, styles: Data<StyleSources>) -> HttpResponse {
let style_id = &path.style_id;
Expand Down
7 changes: 5 additions & 2 deletions martin/src/srv/tiles_info.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::string::ToString;

use actix_middleware_etag::Etag;
use actix_web::error::ErrorBadRequest;
use actix_web::http::Uri;
use actix_web::middleware::Compress;
use actix_web::web::{Data, Path};
use actix_web::{HttpRequest, HttpResponse, Result as ActixResult, middleware, route};
use actix_web::{HttpRequest, HttpResponse, Result as ActixResult, route};
use itertools::Itertools as _;
use serde::Deserialize;
use tilejson::{TileJSON, tilejson};
Expand All @@ -20,7 +22,8 @@ pub struct SourceIDsRequest {
"/{source_ids}",
method = "GET",
method = "HEAD",
wrap = "middleware::Compress::default()"
wrap = "Etag",
wrap = "Compress::default()"
)]
#[allow(clippy::unused_async)]
async fn get_source_info(
Expand Down
4 changes: 4 additions & 0 deletions tests/expected/auto/catalog_auto.json.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
content-encoding: br
content-type: application/json
transfer-encoding: chunked
vary: accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/cmp.json.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: br
content-type: application/json
etag: W/"1a7-SKz0jISgY5NokLA90cn9bQ=="
transfer-encoding: chunked
vary: accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/cmp_0_0_0.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 1150
content-type: application/x-protobuf
etag: "293815559851244067215006259112061301509"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/cmp_12_3673_1911.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 228
content-type: application/x-protobuf
etag: "65126464844181472926168475650420052208"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/cmp_13_7346_3822.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 229
content-type: application/x-protobuf
etag: "285993515030094388663176915274199952144"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/cmp_14_14692_7645.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 241
content-type: application/x-protobuf
etag: "311485364959417352099842717473316722909"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/cmp_17_117542_61161.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 253
content-type: application/x-protobuf
etag: "45271956850074002467276433108641392681"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/cmp_18_235085_122323.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 255
content-type: application/x-protobuf
etag: "27476821680655535149048155649476331810"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/cmp_6_57_29.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 181
content-type: application/x-protobuf
etag: "318858893996331708671731244488057597244"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc.json.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: br
content-type: application/json
etag: W/"85-6Q4dOREWZNsdPdT5r-Pjvg=="
transfer-encoding: chunked
vary: accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_0_0_0.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 546
content-type: application/x-protobuf
etag: "50104397035412006126955407492289337352"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_12_3673_1911.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 131
content-type: application/x-protobuf
etag: "316036929976559733097913904358871580694"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_13_7346_3822.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 133
content-type: application/x-protobuf
etag: "186991199734742473829029472341770943562"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_14_14692_7645.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 141
content-type: application/x-protobuf
etag: "270799230191288586610033918771820004719"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_17_117542_61161.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 146
content-type: application/x-protobuf
etag: "59732876737746661838673831051212271461"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_18_235085_122323.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 150
content-type: application/x-protobuf
etag: "188910840057561700607644193135209710567"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_6_57_29.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 106
content-type: application/x-protobuf
etag: "148595474743525054411317108796671227677"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_b.json.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: br
content-type: application/json
etag: W/"ad-WumWK2dl9zyB9VKNT00Jkg=="
transfer-encoding: chunked
vary: accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_b_6_38_20.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 110
content-type: application/x-protobuf
etag: "339404027429166108039741083243940146201"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_comment.json.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: br
content-type: application/json
etag: W/"102-6tbS_Y0ey_fK7fkhJd4WKQ=="
transfer-encoding: chunked
vary: accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_token.json.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: br
content-type: application/json
etag: W/"aa-aH357MWBb3myW2xPJ6n6iw=="
transfer-encoding: chunked
vary: accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_token_0_0_0.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 551
content-type: application/x-protobuf
etag: "197420765542523001088152476290493617488"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_zoom_xy_6_57_29.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 104
content-type: application/x-protobuf
etag: "313925108765747031844863332687426553785"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_zxy2_6_57_29.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 103
content-type: application/x-protobuf
etag: "134723745777099237261560614323384911032"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_zxy_6_57_29.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 101
content-type: application/x-protobuf
etag: "234076532504863321998415269051837419664"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_zxy_query_6_57_29.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 106
content-type: application/x-protobuf
etag: "148595474743525054411317108796671227677"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_zxy_row2_6_57_29.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 115
content-type: application/x-protobuf
etag: "205494963574970857606832668009198552781"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_zxy_row_6_57_29.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 107
content-type: application/x-protobuf
etag: "133204562788894152562072143322114701432"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/fnc_zxy_row_key_6_57_29.pbf.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: gzip
content-length: 107
content-type: application/x-protobuf
etag: "18077437226671957325453576147625224838"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
5 changes: 5 additions & 0 deletions tests/expected/auto/mb_jpg.json.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
content-encoding: br
content-type: application/json
etag: W/"31fe-1IOZwmkS4fjYIp-JzMoTpA=="
transfer-encoding: chunked
vary: accept-encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers
4 changes: 4 additions & 0 deletions tests/expected/auto/mb_jpg_0_0_0.jpg.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
content-length: 22142
content-type: image/jpeg
etag: "80104354369725283657331287868672010947"
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
Loading
Loading