{"action":"created","comment":{"url":"https://api.github.com/repos/sourcegraph/httpcache/pulls/comments/25076416","id":25076416,"diff_hunk":"@@ -51,7 +55,48 @@ func CachedResponse(c Cache, req *http.Request) (resp *http.Response, err error)\n \t}\n \n \tb := bytes.NewBuffer(cachedVal)\n-\treturn http.ReadResponse(bufio.NewReader(b), req)\n+\treturnResponse, err := http.ReadResponse(bufio.NewReader(b), req)\n+\tif err != nil {\n+\t\treturn nil, fmt.Errorf(\"error loading response from cache: %s\\n\", err.Error())\n+\t}\n+\n+\trangeRaw := req.Header.Get(\"range\")\n+\tif rangeRaw != \"\" {\n+\t\ttmp := strings.Split(rangeRaw, rangeTypeSeparator)\n+\t\t// standard format is bytes=START-END\n+\t\trangetype, rangevalue := tmp[0], tmp[1]\n+\t\tif rangetype != \"bytes\" {\n+\t\t\tfmt.Printf(\"range type %s not supported\\n\", rangetype)\n+\t\t\treturn returnResponse, nil\n+\t\t}\n+\t\t// we need to read all the body now, close it, and replace it with another reader\n+\t\t// as there is currently no way of \"resetting\" a Body\n+\t\tbody, err := ioutil.ReadAll(returnResponse.Body)\n+\t\tif err != nil {\n+\t\t\tfmt.Printf(\"error reading cached response body: %s\\n\", err.Error())\n+\t\t\treturn returnResponse, nil\n+\t\t}\n+\t\treturnResponse.Body.Close()\n+\t\tvar rangedRequestStart, rangedRequestEnd int64\n+\t\t//TODO(uovobw): handle corrupted/nonstandard request header\n+\t\trangeList := strings.Split(rangevalue, rangeSeparator)","path":"httpcache.go","position":51,"original_position":51,"commit_id":"16bd323623903befeff89d652be334ca21c9d9b0","original_commit_id":"16bd323623903befeff89d652be334ca21c9d9b0","user":{"login":"uovobw","id":1194751,"avatar_url":"https://avatars.githubusercontent.com/u/1194751?v=3","gravatar_id":"","url":"https://api.github.com/users/uovobw","html_url":"https://github.com/uovobw","followers_url":"https://api.github.com/users/uovobw/followers","following_url":"https://api.github.com/users/uovobw/following{/other_user}","gists_url":"https://api.github.com/users/uovobw/gists{/gist_id}","starred_url":"https://api.github.com/users/uovobw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uovobw/subscriptions","organizations_url":"https://api.github.com/users/uovobw/orgs","repos_url":"https://api.github.com/users/uovobw/repos","events_url":"https://api.github.com/users/uovobw/events{/privacy}","received_events_url":"https://api.github.com/users/uovobw/received_events","type":"User","site_admin":false},"body":"yep, forgot to handle the comma cases, sorry about that","created_at":"2015-02-20T15:25:41Z","updated_at":"2015-02-20T15:25:41Z","html_url":"https://github.com/sourcegraph/httpcache/pull/2#discussion_r25076416","pull_request_url":"https://api.github.com/repos/sourcegraph/httpcache/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/sourcegraph/httpcache/pulls/comments/25076416"},"html":{"href":"https://github.com/sourcegraph/httpcache/pull/2#discussion_r25076416"},"pull_request":{"href":"https://api.github.com/repos/sourcegraph/httpcache/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/sourcegraph/httpcache/pulls/2","id":29600017,"html_url":"https://github.com/sourcegraph/httpcache/pull/2","diff_url":"https://github.com/sourcegraph/httpcache/pull/2.diff","patch_url":"https://github.com/sourcegraph/httpcache/pull/2.patch","issue_url":"https://api.github.com/repos/sourcegraph/httpcache/issues/2","number":2,"state":"open","locked":false,"title":"Handle range requests","user":{"login":"uovobw","id":1194751,"avatar_url":"https://avatars.githubusercontent.com/u/1194751?v=3","gravatar_id":"","url":"https://api.github.com/users/uovobw","html_url":"https://github.com/uovobw","followers_url":"https://api.github.com/users/uovobw/followers","following_url":"https://api.github.com/users/uovobw/following{/other_user}","gists_url":"https://api.github.com/users/uovobw/gists{/gist_id}","starred_url":"https://api.github.com/users/uovobw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uovobw/subscriptions","organizations_url":"https://api.github.com/users/uovobw/orgs","repos_url":"https://api.github.com/users/uovobw/repos","events_url":"https://api.github.com/users/uovobw/events{/privacy}","received_events_url":"https://api.github.com/users/uovobw/received_events","type":"User","site_admin":false},"body":"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\r\nThe 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\r\nI 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","created_at":"2015-02-19T10:25:51Z","updated_at":"2015-02-20T15:25:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"19cea2d4324e4500c6bf54e69adaf015f9d3ef06","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sourcegraph/httpcache/pulls/2/commits","review_comments_url":"https://api.github.com/repos/sourcegraph/httpcache/pulls/2/comments","review_comment_url":"https://api.github.com/repos/sourcegraph/httpcache/pulls/comments/{number}","comments_url":"https://api.github.com/repos/sourcegraph/httpcache/issues/2/comments","statuses_url":"https://api.github.com/repos/sourcegraph/httpcache/statuses/16bd323623903befeff89d652be334ca21c9d9b0","head":{"label":"uovobw:handle-range-requests","ref":"handle-range-requests","sha":"16bd323623903befeff89d652be334ca21c9d9b0","user":{"login":"uovobw","id":1194751,"avatar_url":"https://avatars.githubusercontent.com/u/1194751?v=3","gravatar_id":"","url":"https://api.github.com/users/uovobw","html_url":"https://github.com/uovobw","followers_url":"https://api.github.com/users/uovobw/followers","following_url":"https://api.github.com/users/uovobw/following{/other_user}","gists_url":"https://api.github.com/users/uovobw/gists{/gist_id}","starred_url":"https://api.github.com/users/uovobw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uovobw/subscriptions","organizations_url":"https://api.github.com/users/uovobw/orgs","repos_url":"https://api.github.com/users/uovobw/repos","events_url":"https://api.github.com/users/uovobw/events{/privacy}","received_events_url":"https://api.github.com/users/uovobw/received_events","type":"User","site_admin":false},"repo":{"id":30898450,"name":"httpcache","full_name":"uovobw/httpcache","owner":{"login":"uovobw","id":1194751,"avatar_url":"https://avatars.githubusercontent.com/u/1194751?v=3","gravatar_id":"","url":"https://api.github.com/users/uovobw","html_url":"https://github.com/uovobw","followers_url":"https://api.github.com/users/uovobw/followers","following_url":"https://api.github.com/users/uovobw/following{/other_user}","gists_url":"https://api.github.com/users/uovobw/gists{/gist_id}","starred_url":"https://api.github.com/users/uovobw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uovobw/subscriptions","organizations_url":"https://api.github.com/users/uovobw/orgs","repos_url":"https://api.github.com/users/uovobw/repos","events_url":"https://api.github.com/users/uovobw/events{/privacy}","received_events_url":"https://api.github.com/users/uovobw/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/uovobw/httpcache","description":"A Transport for http.Client that will cache responses according to the HTTP RFC","fork":true,"url":"https://api.github.com/repos/uovobw/httpcache","forks_url":"https://api.github.com/repos/uovobw/httpcache/forks","keys_url":"https://api.github.com/repos/uovobw/httpcache/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uovobw/httpcache/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uovobw/httpcache/teams","hooks_url":"https://api.github.com/repos/uovobw/httpcache/hooks","issue_events_url":"https://api.github.com/repos/uovobw/httpcache/issues/events{/number}","events_url":"https://api.github.com/repos/uovobw/httpcache/events","assignees_url":"https://api.github.com/repos/uovobw/httpcache/assignees{/user}","branches_url":"https://api.github.com/repos/uovobw/httpcache/branches{/branch}","tags_url":"https://api.github.com/repos/uovobw/httpcache/tags","blobs_url":"https://api.github.com/repos/uovobw/httpcache/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uovobw/httpcache/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uovobw/httpcache/git/refs{/sha}","trees_url":"https://api.github.com/repos/uovobw/httpcache/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uovobw/httpcache/statuses/{sha}","languages_url":"https://api.github.com/repos/uovobw/httpcache/languages","stargazers_url":"https://api.github.com/repos/uovobw/httpcache/stargazers","contributors_url":"https://api.github.com/repos/uovobw/httpcache/contributors","subscribers_url":"https://api.github.com/repos/uovobw/httpcache/subscribers","subscription_url":"https://api.github.com/repos/uovobw/httpcache/subscription","commits_url":"https://api.github.com/repos/uovobw/httpcache/commits{/sha}","git_commits_url":"https://api.github.com/repos/uovobw/httpcache/git/commits{/sha}","comments_url":"https://api.github.com/repos/uovobw/httpcache/comments{/number}","issue_comment_url":"https://api.github.com/repos/uovobw/httpcache/issues/comments/{number}","contents_url":"https://api.github.com/repos/uovobw/httpcache/contents/{+path}","compare_url":"https://api.github.com/repos/uovobw/httpcache/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uovobw/httpcache/merges","archive_url":"https://api.github.com/repos/uovobw/httpcache/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uovobw/httpcache/downloads","issues_url":"https://api.github.com/repos/uovobw/httpcache/issues{/number}","pulls_url":"https://api.github.com/repos/uovobw/httpcache/pulls{/number}","milestones_url":"https://api.github.com/repos/uovobw/httpcache/milestones{/number}","notifications_url":"https://api.github.com/repos/uovobw/httpcache/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uovobw/httpcache/labels{/name}","releases_url":"https://api.github.com/repos/uovobw/httpcache/releases{/id}","created_at":"2015-02-17T02:01:27Z","updated_at":"2015-02-17T02:01:27Z","pushed_at":"2015-02-19T14:17:04Z","git_url":"git://github.com/uovobw/httpcache.git","ssh_url":"git@github.com:uovobw/httpcache.git","clone_url":"https://github.com/uovobw/httpcache.git","svn_url":"https://github.com/uovobw/httpcache","homepage":null,"size":228,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"sourcegraph:master","ref":"master","sha":"0a093449159a63ea40c2c2644fe3f27e28250f10","user":{"login":"sourcegraph","id":3979584,"avatar_url":"https://avatars.githubusercontent.com/u/3979584?v=3","gravatar_id":"","url":"https://api.github.com/users/sourcegraph","html_url":"https://github.com/sourcegraph","followers_url":"https://api.github.com/users/sourcegraph/followers","following_url":"https://api.github.com/users/sourcegraph/following{/other_user}","gists_url":"https://api.github.com/users/sourcegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcegraph/subscriptions","organizations_url":"https://api.github.com/users/sourcegraph/orgs","repos_url":"https://api.github.com/users/sourcegraph/repos","events_url":"https://api.github.com/users/sourcegraph/events{/privacy}","received_events_url":"https://api.github.com/users/sourcegraph/received_events","type":"Organization","site_admin":false},"repo":{"id":12821110,"name":"httpcache","full_name":"sourcegraph/httpcache","owner":{"login":"sourcegraph","id":3979584,"avatar_url":"https://avatars.githubusercontent.com/u/3979584?v=3","gravatar_id":"","url":"https://api.github.com/users/sourcegraph","html_url":"https://github.com/sourcegraph","followers_url":"https://api.github.com/users/sourcegraph/followers","following_url":"https://api.github.com/users/sourcegraph/following{/other_user}","gists_url":"https://api.github.com/users/sourcegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/sourcegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourcegraph/subscriptions","organizations_url":"https://api.github.com/users/sourcegraph/orgs","repos_url":"https://api.github.com/users/sourcegraph/repos","events_url":"https://api.github.com/users/sourcegraph/events{/privacy}","received_events_url":"https://api.github.com/users/sourcegraph/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sourcegraph/httpcache","description":"A Transport for http.Client that will cache responses according to the HTTP RFC","fork":true,"url":"https://api.github.com/repos/sourcegraph/httpcache","forks_url":"https://api.github.com/repos/sourcegraph/httpcache/forks","keys_url":"https://api.github.com/repos/sourcegraph/httpcache/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sourcegraph/httpcache/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sourcegraph/httpcache/teams","hooks_url":"https://api.github.com/repos/sourcegraph/httpcache/hooks","issue_events_url":"https://api.github.com/repos/sourcegraph/httpcache/issues/events{/number}","events_url":"https://api.github.com/repos/sourcegraph/httpcache/events","assignees_url":"https://api.github.com/repos/sourcegraph/httpcache/assignees{/user}","branches_url":"https://api.github.com/repos/sourcegraph/httpcache/branches{/branch}","tags_url":"https://api.github.com/repos/sourcegraph/httpcache/tags","blobs_url":"https://api.github.com/repos/sourcegraph/httpcache/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sourcegraph/httpcache/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sourcegraph/httpcache/git/refs{/sha}","trees_url":"https://api.github.com/repos/sourcegraph/httpcache/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sourcegraph/httpcache/statuses/{sha}","languages_url":"https://api.github.com/repos/sourcegraph/httpcache/languages","stargazers_url":"https://api.github.com/repos/sourcegraph/httpcache/stargazers","contributors_url":"https://api.github.com/repos/sourcegraph/httpcache/contributors","subscribers_url":"https://api.github.com/repos/sourcegraph/httpcache/subscribers","subscription_url":"https://api.github.com/repos/sourcegraph/httpcache/subscription","commits_url":"https://api.github.com/repos/sourcegraph/httpcache/commits{/sha}","git_commits_url":"https://api.github.com/repos/sourcegraph/httpcache/git/commits{/sha}","comments_url":"https://api.github.com/repos/sourcegraph/httpcache/comments{/number}","issue_comment_url":"https://api.github.com/repos/sourcegraph/httpcache/issues/comments/{number}","contents_url":"https://api.github.com/repos/sourcegraph/httpcache/contents/{+path}","compare_url":"https://api.github.com/repos/sourcegraph/httpcache/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sourcegraph/httpcache/merges","archive_url":"https://api.github.com/repos/sourcegraph/httpcache/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sourcegraph/httpcache/downloads","issues_url":"https://api.github.com/repos/sourcegraph/httpcache/issues{/number}","pulls_url":"https://api.github.com/repos/sourcegraph/httpcache/pulls{/number}","milestones_url":"https://api.github.com/repos/sourcegraph/httpcache/milestones{/number}","notifications_url":"https://api.github.com/repos/sourcegraph/httpcache/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sourcegraph/httpcache/labels{/name}","releases_url":"https://api.github.com/repos/sourcegraph/httpcache/releases{/id}","created_at":"2013-09-13T22:56:39Z","updated_at":"2015-02-15T13:41:39Z","pushed_at":"2015-02-16T00:29:39Z","git_url":"git://github.com/sourcegraph/httpcache.git","ssh_url":"git@github.com:sourcegraph/httpcache.git","clone_url":"https://github.com/sourcegraph/httpcache.git","svn_url":"https://github.com/sourcegraph/httpcache","homepage":null,"size":228,"stargazers_count":9,"watchers_count":9,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":1,"forks":3,"open_issues":1,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sourcegraph/httpcache/pulls/2"},"html":{"href":"https://github.com/sourcegraph/httpcache/pull/2"},"issue":{"href":"https://api.github.com/repos/sourcegraph/httpcache/issues/2"},"comments":{"href":"https://api.github.com/repos/sourcegraph/httpcache/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/sourcegraph/httpcache/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/sourcegraph/httpcache/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/sourcegraph/httpcache/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/sourcegraph/httpcache/statuses/16bd323623903befeff89d652be334ca21c9d9b0"}}}}