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

Support range requests more conveniently #17

Open
dcoutts opened this issue Jul 17, 2015 · 2 comments
Open

Support range requests more conveniently #17

dcoutts opened this issue Jul 17, 2015 · 2 comments
Assignees

Comments

@dcoutts
Copy link

dcoutts commented Jul 17, 2015

Would be nice to have something to support range requests more conveniently.

There's two cases here:

  • general content, some filter or helper ToMessage instance that does the right thing (including setting the response code, length and range headers, stripping of content-md5 etc).
  • send file, it should be easy enough to support single-range range requests because SendFile supports offset and count.
@stepcut stepcut self-assigned this Sep 18, 2015
@stepcut
Copy link
Member

stepcut commented Sep 18, 2015

This seems important. Time to read some RFCs.

@stepcut
Copy link
Member

stepcut commented Mar 19, 2016

I have attempted to implement support for ByteRanges in this branch:

https://github.com/Happstack/happstack-server/tree/byteranges

I can support both single-range and multi-range requests with SendFile.

It turns out that lazy ByteStrings are a bit of an issue. It seems that something is holding onto a reference to the original Response, so even though I attempt to carve out the request byterange(s) from the body in a GC friendly way -- you can still force the whole lazy ByteString into RAM by requesting the last byte.

I have a feeling that fixing this will require some significant changes to happstack-server, such as changing the Response body to be wrapped in an IORef, or something else not so good.

My inclination is to punt on this for now and instead focus my time on hyperdrive where it should be easy to do it right.

If limited support for byteranges that only worked with SendFile responses would be useful for hackage-server, I'd be willing to carve out and support just the subset of functionality that hackage-server needs for now.

If someone wants to try to fix the lazy ByteString space leak, uncomment this test:

https://github.com/Happstack/happstack-server/blob/byteranges/tests/Happstack/Server/RangeTest.hs#L208

will cause the test suite to gobble RAM.

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