Skip to content

Made the fileserver component accept file routes#53

Merged
itowlson merged 2 commits into
spinframework:mainfrom
benwis:main
Mar 13, 2024
Merged

Made the fileserver component accept file routes#53
itowlson merged 2 commits into
spinframework:mainfrom
benwis:main

Conversation

@benwis
Copy link
Copy Markdown
Contributor

@benwis benwis commented Mar 13, 2024

Wanted to be able to specify specific files so that it wouldn't capture the root wildcard route. Should close #52

Signed-off-by: benwis <ben@celcyon.com>
@itowlson itowlson requested review from dicej and jpflueger March 13, 2024 00:14
Copy link
Copy Markdown
Contributor

@itowlson itowlson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! I've run into the favicon problem myself a few times and it will be nice to have a way to tackle it!

Comment thread src/lib.rs Outdated
.expect("COMPONENT_ROUTE header must be set by the Spin runtime");

let uri = req.uri().parse::<Uri>().expect("URI is invalid").path().as_bytes().to_vec();
if &uri == component_route && path.is_empty(){
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will not match in the presence of a HTTP trigger application-level base route.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vdice tells me the file server doesn't work in the presence of a base anyway so :shipit:

Comment thread src/lib.rs Outdated

let uri = req.uri().parse::<Uri>().expect("URI is invalid").path().as_bytes().to_vec();
if &uri == component_route && path.is_empty(){
path = &uri;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it would require the file to be mapped into the component at the component path e.g. if the route is /pictures/special/cat.jpg then the file must be mapped to pictures/special/cat.jpg. Are we comfortable with this requirement?

@benwis
Copy link
Copy Markdown
Contributor Author

benwis commented Mar 13, 2024 via email

Signed-off-by: benwis <ben@celcyon.com>
Copy link
Copy Markdown
Contributor

@itowlson itowlson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @benwis I just spotted a nasty which I think could cause problems on Cloud.

Comment thread src/lib.rs
.expect("COMPONENT_ROUTE header must be set by the Spin runtime");

let uri = req
.uri()
Copy link
Copy Markdown
Contributor

@itowlson itowlson Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed this - sorry. I'd avoid req.uri() because it's not well specified: some implementations provide the "URI you'd see in the browser with host and scheme and everything" and others provide only the "URL as seen on the first line of the HTTP protocol" which everyone else calls the path - and the latter doesn't parse. (See https://developer.fermyon.com/spin/v2/http-trigger#getting-request-and-response-information which says it's the latter, but I think the CLI confusingly gives you the former, and then on Cloud you get a nasty surprise.) It's intensely frustrating and I wish we could sort it out, but for now you really need to use the spin-full-url header.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benwis False alarm, sorry... the behaviour is inconsistent, but the parse still succeeds in both places. Apologies for jumping to conclusions!

@benwis
Copy link
Copy Markdown
Contributor Author

benwis commented Mar 13, 2024 via email

@itowlson
Copy link
Copy Markdown
Contributor

@benwis No, I messed up. No need to change.

@itowlson itowlson merged commit e877bb6 into spinframework:main Mar 13, 2024
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.

Exact routes serving single files

2 participants