-
Notifications
You must be signed in to change notification settings - Fork 284
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
fix #716 (Add partial content with range) #1634
Conversation
Using this on my websites now and everything seems to work as expected and users don't complain about video playback anymore. (Asked them explicitly for issues) |
auto range = (*prange).chompPrefix("bytes="); | ||
auto s = range.split("-"); | ||
// https://tools.ietf.org/html/rfc7233 | ||
// Range can be in form "-\d", "\d-" or "\d-\d" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The range can also have "/\d+" or "/*" as an additional suffix, and multiple ranges can be separated by comma. We should probably check that s.length == 2
and that range.canFind(',')
. Actually supporting this feature seems less important, though.
Edit: Misread the part with the slash suffix, that applies really only to the response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"" - not sure if that's just my browser, but that's supposed to be a backslash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really know how to send the response back to the user when there is a comma in the request. Like imagine you request the first and last character, should the response be both characters combined together or should it be different?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to be sent using a multi-part response. But I'd just send a 400 Bad Request back instead, as I don't think that any typical client will ever request multiple ranges.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...or rather 501 Not Implemented
Instead of The functionality itself looks good AFAICS. |
Okay, looks good to merge. Thanks for tackling this! I'll look into adding a test after the merge. |
if (s[0].length) { | ||
rangeStart = s[0].to!ulong; | ||
rangeEnd = s[1].length ? s[1].to!ulong : dirent.size; | ||
} else if (s[1].length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to check length
of s
before you access s[1]
.
The client can send malformed headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh well this PR is merged already and I recreated the repo so I can't edit this anymore, I will make a separate PR.
fix #716 (Add partial content with range)
Mostly based on #716 (comment)
Changes to that comment: added
-[X]
format and sending partialContent status code. Also some cleaner code and checks against bad requests.Not sure how to add an automatic test but I did manually test it locally using this very simple file server in chrome and firefox:
My aim was only fixing media streams (audio & video + seeking), but pausing downloads and resuming also works now.