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

How can I specify headers for one request? #284

Closed
JakubMrozek opened this issue Sep 6, 2014 · 6 comments · May be fixed by theWindSweptDev/google-api-nodejs-client#2
Closed

How can I specify headers for one request? #284

JakubMrozek opened this issue Sep 6, 2014 · 6 comments · May be fixed by theWindSweptDev/google-api-nodejs-client#2
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@JakubMrozek
Copy link

It is possible? I need different headers for every requests. In the previos version, there was a simple method setHeaders(), but I don't know how to specify header options only for one request now.

@ryanseys
Copy link
Contributor

ryanseys commented Sep 6, 2014

Hmm, I'm curious why you need to do this?

You can specify additional settings when you initialize the googleapis object that are 1:1 mapping of mikeal/request options but those will get applied to every request.

Example (apply Content-Type: 'application/json' header to every request):

var google = require('googleapis');
google.options({ headers: { 'Content-Type': 'application/json' } });

You shouldn't need to do this though so I'm curious why (maybe we can fill some developer need here)?

@ryanseys
Copy link
Contributor

ryanseys commented Sep 6, 2014

There isn't really a nice way to apply headers to a single request right now. If you can make a good case for it, this might help push along such a feature.

@JakubMrozek
Copy link
Author

I want to set Etag header, which is diferrent for every request (for different resource). I fixed this in my fork: https://github.com/JakubMrozek/google-api-nodejs-client/blob/master/lib/apirequest.js#L150 I can send a pull request if you want...

@ryanseys
Copy link
Contributor

ryanseys commented Sep 6, 2014

This will work for most cases unless an api endpoint uses 'headers' as a property name for some parameter. I find that event unlikely to happen, but this is reason why we try to limit the number of additional properties on the top level object specified in a request.

@rakyll perhaps you can chime in here about a reasonable trade-off for specifying additional options per-request?

@ryanseys
Copy link
Contributor

What API are using the ETag header with? In the Drive API for example, you can specify the ETag of a files resource by using params.etag

See https://developers.google.com/drive/v2/reference/files#resource

Does the API you're using support a similar value? If not, I can consider merging your params.headers diff if you send a PR. Seems no API uses params.headers as a property name so we should be pretty safe to use it.

@ryanseys
Copy link
Contributor

@JakubMrozek does the params.etag work for you like suggested above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants