Skip to content

Add serve_file method to route#725

Merged
yoshuawuyts merged 6 commits intohttp-rs:mainfrom
mendelt:serve_file_endpoint
Dec 4, 2020
Merged

Add serve_file method to route#725
yoshuawuyts merged 6 commits intohttp-rs:mainfrom
mendelt:serve_file_endpoint

Conversation

@mendelt
Copy link
Contributor

@mendelt mendelt commented Oct 21, 2020

This pr adds a serve_file method alongside the already existing serve_dir method.

Copy link
Member

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

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

seems reasonable

@mendelt mendelt force-pushed the serve_file_endpoint branch from 4f2d5b1 to 8f2208b Compare October 21, 2020 20:56
@mendelt
Copy link
Contributor Author

mendelt commented Oct 21, 2020

I added serve_file to Route to be consistent with how serve_dir works for now.
Personally I would like the Route struct to stay a bit cleaner. We could add specific helper methods like serve_dir and serve_file with extension traits, that way helper methods like this can be added to Route by importing the extension traits you need.
Does anyone have an opinion on this?

@mendelt mendelt marked this pull request as ready for review October 21, 2020 21:12
Copy link
Member

@goto-bus-stop goto-bus-stop left a comment

Choose a reason for hiding this comment

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

I don't think an extension trait is necessary at this stage. There are only a few different methods on the trait, if you count the 10 HTTP method aliases as one 😜

@mendelt
Copy link
Contributor Author

mendelt commented Oct 22, 2020

I don't think an extension trait is necessary at this stage. There are only a few different methods on the trait, if you count the 10 HTTP method aliases as one stuck_out_tongue_winking_eye

Funny you put it that way. Because in my fluent routes crate I put all of those aliases in their own extension trait too :-) https://github.com/mendelt/tide-fluent-routes/blob/c20244d6e2254f275ebc0ad46ebed2c621ef90a6/src/routebuilder.rs#L27

But for now this might be a bit premature, and I'd want to put serve_dir in an extension trait too. And that will break backward compatibiltiy. So yeah, this might be for later if there are more routing helper methods.

@mendelt mendelt closed this Oct 22, 2020
@mendelt mendelt reopened this Oct 22, 2020
@mendelt mendelt force-pushed the serve_file_endpoint branch from 775b9f6 to 5ad0903 Compare December 1, 2020 22:52
Copy link
Member

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

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

Thanks so much for this PR @mendelt; this looks good!

In the past there's been talk about perhaps moving serve / serve_file into some sort of FileServer struct which would resemble much of how Tide's redirects work today. But we still need to finish up the design for that, and I don't think we should miss out on a chance to make serving single files easier until then.

Going to go ahead and merge this; thanks heaps!

@yoshuawuyts
Copy link
Member

Tested this locally, and clippy + rustfmt pass. We need to update the CI, but in the interim I think this is fine to merge as-is. Thanks!

@yoshuawuyts yoshuawuyts merged commit 5ba6340 into http-rs:main Dec 4, 2020
@mendelt mendelt deleted the serve_file_endpoint branch December 12, 2020 22:06
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.

4 participants