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

BaseRequest.http_range returns the wrong slice when "start" is missing #2805

Closed
Fahrradkette opened this issue Mar 6, 2018 · 5 comments
Closed
Labels

Comments

@Fahrradkette
Copy link
Contributor

Long story short

When streaming range based requests from file, the method http_range comes quite handy, unfortunately negative indexes don't work as expected.

The offending line 442 is in web_request.py it should be "start = -end" instead of "end = -end"

Other valid ranges are described in https://tools.ietf.org/html/rfc7233#section-2.1
I don't know if it's allowed to just return a 416 on the more exotic ones though:)

Expected behaviour

[Request Header]
Range: bytes=-5678

[BaseRequest.http_range]
slice(start=-5678, stop=None, step=1)

Actual behaviour

[Request Header]
Range: bytes=-5678

[BaseRequest.http_range]
slice(start=None, stop=-5678, step=1)

Steps to reproduce

run an aiohttp server and request a resource using the range header.
(do I have to post the whole setup, code included?)

Your environment

Running aiohttp 1.2.0 on debian 9 (stretch) ... I know, I know :)

@asvetlov
Copy link
Member

asvetlov commented Mar 7, 2018

Would you make a pull request?

@ikanobori
Copy link

ikanobori commented Mar 7, 2018

While what @Fahrradkette reported would be a nice and clean pull request to fix (and if he doesn't have the time/need I can take a stab at that) the problem is deeper than what is described in this ticket.

According to the RFC https://tools.ietf.org/html/rfc7233 section 2.1 the following are all valid range requests (when concerning bytes):

bytes=0-499
bytes=500-999
bytes=-500
bytes=9500-

The above can all be easily supported and are as you expect. However the following are also valid:

bytes=500-600,601-999
bytes=500-700,601-999

Where the response would be a multipart with those byte ranges. However currently in the above mentioned function only a single slice can be returned :)

What are your ideas on supporting the entire Range grammar which would likely be much more complex versus just fixing the first part of it.

My opinion is to either support all of Range or none.

@asvetlov
Copy link
Member

asvetlov commented Mar 7, 2018

I doubt if multi-range requests are wide spread. Lets keep the single range for simplicity.
Multiranges require a new property anyway, we cannot do it with existing property without breaking backward compatibility.
Raising an exception in case of multirange is pretty fibe.

@ikanobori
Copy link

In that case if @Fahrradkette wants to create a pull request they can, otherwise I can.

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants