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

Oauth not working request with headers.Accept='application/pdf' #8

Closed
mgilgar opened this issue Mar 2, 2014 · 3 comments
Closed

Oauth not working request with headers.Accept='application/pdf' #8

mgilgar opened this issue Mar 2, 2014 · 3 comments

Comments

@mgilgar
Copy link

mgilgar commented Mar 2, 2014

I am trying to GET some content in 'application/pdf' format (PDF 1.4). I specify in the headers headers.Accept='application/pdf' and I get content that display an empty file in any PDF viewer but the file is not empty. Have a look at this code in lib/oauth.js:

if ($this.clientOptions.detectResponseContentType && utils.isBinaryContent(response)) {
data = new Buffer(0);
type = 1;
output = response;
} else if (response.headers['content-encoding'] === 'gzip') {
var gunzip = zlib.createGunzip();
data = new Buffer(0);
type = 2;
response.pipe(gunzip);
output = gunzip;
} else {
response.setEncoding('utf8');
data = "";
output = response;
}

$this.clientOptions.detectResponseContentType is undefined and it is not documented what it does or how to set it up anyway.
In regards to isBinaryContent function it returns false for PDF.
So it is the else what it is run, so we run this line:
response.setEncoding('utf8')

I have fixed it locally by adding this:
if ($this.clientOptions.detectResponseContentType && utils.isBinaryContent(response)) {
data = new Buffer(0);
type = 1;
output = response;
} else if (response.headers['content-encoding'] === 'gzip') {
var gunzip = zlib.createGunzip();
data = new Buffer(0);
type = 2;
response.pipe(gunzip);
output = gunzip;
} else if (headers.Accept=='application/pdf') {
data = new Buffer(0);
type = 1;
output = response;
} else {
response.setEncoding('utf8');
data = "";
output = response;
}

This is more a hack than a solution but I am not sure is PDF is binary file format and I am not sure how do you use $this.clientOptions.detectResponseContentType.

@nijikokun
Copy link
Contributor

I check for text based entities instead of binary now. And you can set that through the setClientOptions function.

I don't think I documented this because it's very advanced.

OAuth.prototype.setClientOptions = function (options) {
  this.clientOptions = utils.extend(this._clientOptions, options);
};

@mgilgar
Copy link
Author

mgilgar commented Mar 3, 2014

You missed a closing parethensis:

utils.isBinaryContent = function (response) {
return (!response.headers || !response.headers["content-type"])
? false
: (response.headers["content-type"].match(/^(text|html|json|doc|xml|html|rss|form|javascript|ecmascript)/)
? false
: true;
};

Should be:
: true);
};

@nijikokun
Copy link
Contributor

Ah thank you

On Mon, Mar 3, 2014 at 1:51 PM, Miguel notifications@github.com wrote:

You missed a closing parethensis:

utils.isBinaryContent = function (response) {
return (!response.headers || !response.headers["content-type"])
? false
:
(response.headers["content-type"].match(/^(text|html|json|doc|xml|html|rss|form|javascript|ecmascript)/)
? false
: true;
};

Should be:
: true);
};

Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-36564516
.

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

No branches or pull requests

2 participants