Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static file serving #4

Open
scottlamb opened this issue Feb 28, 2017 · 4 comments
Open

static file serving #4

scottlamb opened this issue Feb 28, 2017 · 4 comments

Comments

@scottlamb
Copy link

As mentioned on reddit: I noticed you have "static file serving" described as a required feature for a 1.0 release.

A plug: https://github.com/scottlamb/http-entity is intended to be useful for this: it handles the conditional GET, byte range serving, and such. The hyper-0.11.x branch is async. You're most welcome to use them if you find them helpful; and if you don't find them helpful, I'd like to fix that.

My crate's young. There's no continuous build yet; the docs haven't gotten much attention; the APIs aren't stable yet; and I'm not in love with the current names http-entity and http-file. On the bright side, that means it's a good time if you have strong opinions on these things. Some possible upcoming API changes:

  • the type of a given Entity's body stream and chunk type could become associate types rather than the current generics.
  • http_entity::serve could become a trait method rather than its current free function. My habit is pure interfaces from languages such as Go, but it seems a lot of Rust stuff such as futures puts a lot of functionality in trait methods that the implementer doesn't need to override.
  • http_file::ChunkedReadFile::new could move into a builder.
@moosingin3space
Copy link
Owner

That crate looks useful. Could you make a branch to demonstrate how hyproxy might use it?

@moosingin3space
Copy link
Owner

Also, thoughts on this crate? https://crates.io/crates/tk-sendfile

@scottlamb
Copy link
Author

That crate looks useful. Could you make a branch to demonstrate how hyproxy might use it?

Hmm, that's a little more than I was looking to do. I extracted http-entity out of another server I'm working on; I want to share the parts that are useful to others, but I don't want to get too distracted from where I started by plugging http-entity into other servers myself. I'm definitely open to changes to http-entity that would make it more useful to you, though.

Also, thoughts on this crate? https://crates.io/crates/tk-sendfile

Looks neat; one could make a http_entity::Entity implementation that uses sendfile (getting the zero-copy of tk-sendfile and the conditional GET / byte range serving of http-entity) , but it'd require changes to hyper; see this comment.

You can do an mmap implementation today (my server does in fact), and it's faster for large files, but there's a significant caveat: your server will crash with SIGBUS if the file is truncated as you're serving it, so you really only want to do this for files you know aren't going to be touched. Also, to avoid stalling the reactor thread, you want to use mlock, and in some cases that requires modifying /etc/security/limits.conf (adding a * - memlock unlimited line), so there's some additional administrative work required.

@moosingin3space
Copy link
Owner

moosingin3space commented Mar 7, 2017 via email

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

No branches or pull requests

2 participants