Skip to content

Loading…

Default custom headers #49

Merged
merged 1 commit into from

3 participants

@MarceloEmmerich

in apiconfig.json, you can add "headers" : {} to a config entry to use
default headers. Format is:

"header" : { "key1":"value1", "key2":"value2", ... }

@MarceloEmmerich MarceloEmmerich support for default headers
in apiconfig.json, you can add "headers" : {} to a config entry to use
default headers. Format is:

"header" : { "key1":"value1", "key2":"value2", ...  }
4f0a531
@haimich

Hi Marcelo,

I tried out your commit and it worked very well! The only thing I noticed was when I wrote

"headers" : {"Accept":"application/json", "Content-Type":"application/json"}

in the apiconfig.json, the quotes of "Accept" were removed in the console output:

headers:
{ Accept: 'application/json',
'Content-Type': 'application/json' }

But I'm not sure if this is important.

@haimich

Another phenomenon I experienced during testing was that I/O Docs tends to overwrite the content-type header in certain cases. This line:

"headers" : {"Accept":"application/json;charset=UTF-8", "Content-Type":"application/json;charset=UTF-8"},

became

headers: 
   { Accept: 'application/json;charset=UTF-8',
     'Content-Type': 'application/x-www-form-urlencoded',
     'Content-Length': 371 }

when calling a service via post and transferring a json value.

@mansilladev

@haimich - re: quotes being removed from "Accept", that should not matter. The quotes are only passed when there are multiple words in the header property name (e.g. "Content-type", "Content-length").

Also, @haimich, the Content-Type overwrite is taking place around line 535. After I merge in this pull request, I'll patch a fix that checks if an option.header exists for Content-Type.

@mansilladev mansilladev merged commit 381a92e into mashery:master
@mansilladev

@MarceloEmmerich - thanks for the improvement. I've merged it in. I've also addressed @haimich issue with the content-type being overridden when there's a request body (for POST/PUT) calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 12, 2012
  1. @MarceloEmmerich

    support for default headers

    MarceloEmmerich committed
    in apiconfig.json, you can add "headers" : {} to a config entry to use
    default headers. Format is:
    
    "header" : { "key1":"value1", "key2":"value2", ...  }
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 1 deletion.
  1. +1 −1 app.js
  2. +1 −0 public/data/apiconfig.json
View
2 app.js
@@ -310,7 +310,7 @@ function processRequest(req, res, next) {
var paramString = query.stringify(params),
privateReqURL = apiConfig.protocol + '://' + apiConfig.baseURL + apiConfig.privatePath + methodURL + ((paramString.length > 0) ? '?' + paramString : ""),
options = {
- headers: {},
+ headers: apiConfig.headers,
protocol: apiConfig.protocol + ':',
host: baseHostUrl,
port: baseHostPort,
View
1 public/data/apiconfig.json
@@ -4,6 +4,7 @@
"protocol": "http",
"baseURL": "api.klout.com",
"publicPath": "/1",
+ "headers" : {},
"auth": "key",
"keyParam": "key"
},
Something went wrong with that request. Please try again.