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

Removing the "If-Modified-Since" request header when the cache is empty (as it causes issues) #104

Merged
merged 2 commits into from
Aug 14, 2016

Conversation

divdavem
Copy link
Contributor

@divdavem divdavem commented Jun 7, 2016

octokat failed today on my machine because GitHub returned a 304 status code when the cache was empty. I think that sending an "If-Modified-Since" header is wrong when we don't expect a 304 response status. Removing the "If-Modified-Since" header in the request fixed my issue, that's why I am opening this pull request

Here is a js file with which you can reproduce the issue on node.js (after making sure the co and octokat npm packages are installed):

"use strict";

const co = require("co");
const Octokat = require("octokat");

co(function * () {
    const octokat = new Octokat({
       // note that I used a token here because my ip was otherwise rate-limited 
    });
    const response = yield octokat.repos("ariatemplates", "ariatemplates").commits.fetch({
        sha: "master"
    });
    console.log(response);
}).catch(function (error) {
    console.log("Error", error);
});

Here is the output I got:

D:\git_clones\t\test\node_modules\octokat\dist\node\plugins\cache-handler.js:51
            throw new Error('ERROR: Bug in Octokat cacheHandler. It had an eTag but not the cached response');
            ^

Error: ERROR: Bug in Octokat cacheHandler. It had an eTag but not the cached response
    at CacheHandler.module.exports.CacheHandler.responseMiddleware (D:\git_clones\t\test\node_modules\octokat\dist\node\plugins\cache-han
dler.js:51:19)
    at Object.instance._parseWithContext (D:\git_clones\t\test\node_modules\octokat\dist\node\base.js:124:39)
    at D:\git_clones\t\test\node_modules\octokat\dist\node\requester.js:207:38
    at xhr.onreadystatechange (D:\git_clones\t\test\node_modules\octokat\dist\node\requester.js:37:18)
    at dispatchEvent (D:\git_clones\t\test\node_modules\xmlhttprequest\lib\XMLHttpRequest.js:591:25)
    at setState (D:\git_clones\t\test\node_modules\xmlhttprequest\lib\XMLHttpRequest.js:610:14)
    at IncomingMessage.<anonymous> (D:\git_clones\t\test\node_modules\xmlhttprequest\lib\XMLHttpRequest.js:447:13)
    at emitNone (events.js:72:20)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:903:12)

I tried with version 0.5.0-beta.0 of octokat but previous versions also failed in a different way (returning an empty string instead of an error).

Note that I have successfully used the octokat package several times with requests similar to this one, so this issue probably comes from a change on GitHub servers.

Thank you in advance for taking this pull request into account.
Thank you for the great work you are doing by providing octokat to the community!

@marnen
Copy link

marnen commented Jul 7, 2016

Please consider merging this. The If-Modified-Since header does indeed seem to be causing problems.

@philschatz
Copy link
Owner

Thank you for fixing this, these changes will be in the next release!

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

Successfully merging this pull request may close these issues.

3 participants