Skip to content
This repository was archived by the owner on May 29, 2018. It is now read-only.

Comments

Handle range requests#2

Open
uovobw wants to merge 22 commits intosourcegraph:masterfrom
uovobw:handle-range-requests
Open

Handle range requests#2
uovobw wants to merge 22 commits intosourcegraph:masterfrom
uovobw:handle-range-requests

Conversation

@uovobw
Copy link

@uovobw uovobw commented Feb 19, 2015

This change handles Range requests by replacing the response.Body object to an in-memory buffer that is created adhoc from the Range header and the size of the Body. It currently relies on the notion that the incoming range will be compliant in both form and content, a TODO has been added for future fix
The tests that are added are primed to first fetch the request to let it be stored in a new in-memory cache for each test and then re-perform the same request to verify range capabilities
I added some comments where the code might not be straightforward and go fmtd all my changes (i have not fmted the rest since it would dirty up the diff, i think it can be done at a later stage), i have used ALLCAPS for constants

httpcache.go Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Use CamelCase for consistency with the stdlib (see http://www.reddit.com/r/golang/comments/2az1fz/convention_for_nonexported_constans/ for a discussion of this).

@uovobw
Copy link
Author

uovobw commented Feb 19, 2015

updated by renaming constants

httpcache.go Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Why did you choose to omit the error checks?

Copy link
Author

Choose a reason for hiding this comment

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

for the same reason i left the out the checks at line 81: if the request is broken it should get as it is to the server so that it might return a 400 or a relevant error, it's not the job of a caching proxy to validate these errors. the problem would be on the client sending a broken request and the error needs to bubble up on the server so that it can get fixed. just my opinion of course, it can be changed. what to do in that case though? removing the range header and letting the request through sounds wrong, giving an error before the server does too..suggestions?

@sqs
Copy link
Member

sqs commented Feb 20, 2015

  • Add tests (and perhaps implement the necessary functionality) for the following scenario: (1) request range 0-10 (no cache hit); (2) request range 4-6 (cache hit because it is a subset of the cached data)

httpcache.go Outdated
Copy link
Member

Choose a reason for hiding this comment

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

It's not necessary (for our needs) and probably not as useful to support multiple byte range requests (e.g., specifying multiple ranges with comma separators; see http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p5-range-latest.html#rule.ranges-specifier), but it should not produce incorrect behavior in that case. (Currently it would fail to parse the ints because they would include commas, and then it would return a 0-range response, I believe.)

Copy link
Author

Choose a reason for hiding this comment

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

yep, forgot to handle the comma cases, sorry about that

…filling the first one

Added check for rangeStart to be less than rangeEnd
Added validateRanges to handle the case we have a subrange of an already existing query
@uovobw
Copy link
Author

uovobw commented Feb 20, 2015

New version that addresses your comments, i also have the PR for removing gocheck but i will make it wait until i can merge it with this one

@uovobw
Copy link
Author

uovobw commented Feb 23, 2015

any news on this?

httpcache.go Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Compile this regexp in init to avoid runtime perf hit

@sqs
Copy link
Member

sqs commented Feb 23, 2015

Is the Content-Range header being set on responses to indicate which byte ranges were actually fulfilled? I don't see where that is occurring. I think this is important if we silently ignore byte ranges we don't support (such as multiple byte ranges). Another option is to error instead of just logging that we don't support a byte range.

httpcache.go Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Instead of logging this, remove the else block from the if-statement and make its statements be the end of this function.

@sqs
Copy link
Member

sqs commented Feb 23, 2015

Also, in addition to the unit tests, have you tried testing this in the real world? Testing against Amazon S3 would be great - it respects range headers (although only single byte ranges, which is OK since that's all this needs to support for now). Even if it's quick manual testing.

sqs and others added 6 commits February 23, 2015 14:24
Reformat SetLogging() to SetLogger that takes a *log.Logger
Check more errors in the code
Set content-range header for ranged responses
Add more checks to the tests (for ranges and headers)
Avoid answering with a partial range to a multiple-range request, answer
by refetching the request again
Add cmd/cacheproxy that contains a standalone caching proxy
@dmitshur
Copy link

Ping @uovobw, what's the status of this PR?

@dmitshur
Copy link

@sqs, do you know the status of this PR? It has had no activity since March 18, 2015, and @uovobw doesn't seem to be responding.

@uovobw
Copy link
Author

uovobw commented Mar 10, 2016

@shurcooL i am responding, i am no longer working or having any contact with sourcegraph so the pr has not been updated since then. the support for the range requests was partial and i had no feedback from @sqs, i think it can be deleted as either no longer relevant or needing way too much work to be made relevant again. hope this helps, let me know

@dmitshur
Copy link

Thanks for providing context @uovobw, that's helpful!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants