Skip to content

Proxy static files - #141

Merged
flenter merged 8 commits into
autometrics-dev:mainfrom
flenter:proxy_static_files
Sep 19, 2023
Merged

flenter merged 8 commits into
autometrics-dev:mainfrom
flenter:proxy_static_files

Conversation

@flenter

@flenter flenter commented Sep 18, 2023 •

Copy link
Copy Markdown
Member

This is mostly required to make service workers work for /explorer. The static assets can't be hosted on a CDN anymore, so this PR now proxies the files. It's also possible to override this target URL to point to something different then the default explorer.autometrics.dev. This way it's possible for developers working on the explorer front-end to test things without needing to deploy it.

Checklist

  • [ x] Changelog updated

Resolves #142

@flenter
flenter requested a review from a team as a code owner September 18, 2023 09:38
@flenter

flenter commented Sep 18, 2023

Copy link
Copy Markdown
Member Author

There's an issue with this proxy functionality that I've not been able to resolve and that's related to http/2. Right now the proxying works however in the terminal the following is logged:

Connection header illegal in HTTP/2: connection

The Connection: keep-alive header that my browser sends is proxied, but isn't actually valid in an http/2 context. Fixing this goes a bit further than my current rust knowledge

@gagbo

gagbo commented Sep 18, 2023 •

Copy link
Copy Markdown
Contributor

There's an issue with this proxy functionality that I've not been able to resolve and that's related to http/2. Right now the proxying works however in the terminal the following is logged:

Connection header illegal in HTTP/2: connection

The Connection: keep-alive header that my browser sends is proxied, but isn't actually valid in an http/2 context. Fixing this goes a bit further than my current rust knowledge

The way I understand the issue, this patch should work

diff --git a/src/bin/am/server/assets.rs b/src/bin/am/server/assets.rs
index 5dd3165..9caf438 100644
--- a/src/bin/am/server/assets.rs
+++ b/src/bin/am/server/assets.rs
@@ -1,6 +1,7 @@
 use crate::server::util::proxy_handler;
 use axum::body::Body;
 use axum::response::IntoResponse;
+use http::header::CONNECTION;
 use url::Url;

 pub async fn handler(mut req: http::Request<Body>, upstream_base: Url) -> impl IntoResponse {
@@ -12,5 +13,6 @@ pub async fn handler(mut req: http::Request<Body>, upstream_base: Url) -> impl I
         .replace("/explorer/static", "/static")
         .parse()
         .unwrap();
+    req.headers_mut().remove(CONNECTION);
     proxy_handler(req, upstream_base.clone()).await
 }

I don't think there's a way to tell the request to "remove all HTTP/2 illegal headers", so we might have to do this on a case by case basis :(

EDIT: also, the request is eventually handled by reqwest::Client, and I don't know whether there's a way to know at runtime whether we're using http1 or 2 (or 3, if using the unstable support)

@flenter

flenter commented Sep 18, 2023

Copy link
Copy Markdown
Member Author
req.headers_mut().remove(CONNECTION);

Thank you for this suggestion! I've modified the code matching your suggestion and the complaints no longer show up in the terminal. 🙏

Comment thread src/bin/am/server/assets.rs Resolved
Comment thread src/bin/am/server/assets.rs Resolved
Comment thread src/bin/am/commands/start.rs Resolved
Comment thread files/autometrics-shared Resolved
Comment thread CHANGELOG.md Resolved
@flenter
flenter merged commit b476613 into autometrics-dev:main Sep 19, 2023
@flenter
flenter deleted the proxy_static_files branch September 19, 2023 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notifications not working for explorer

3 participants