Skip to content

Commit

Permalink
Accept headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima Shirokov authored and kaizensoze committed Oct 8, 2016
1 parent 9fe50d6 commit 0704c0e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ var Client = module.exports = function(config) {
this.config.pathPrefix = pathPrefix;
}

(() => {
let mediaHash = this.routes.defines.acceptTree;
let mediaTypes = {};

for(let accept in mediaHash) {
for(let i in mediaHash[accept])
mediaTypes[mediaHash[accept][i]] = accept;
}

this.acceptUrls = mediaTypes;
})();

this.setupRoutes();
};

Expand Down Expand Up @@ -692,8 +704,8 @@ var Client = module.exports = function(config) {
headers["user-agent"] = "NodeJS HTTP Client";

if (!("accept" in headers))
headers["accept"] = this.config.requestMedia || this.constants.requestMedia;

headers["accept"] = this.acceptUrls[block.url] || this.config.requestMedia || this.constants.requestMedia;
var options = {
host: host,
port: port,
Expand Down
86 changes: 86 additions & 0 deletions lib/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,92 @@
"invalidmsg": "",
"description": "OAuth token"
}
},
"acceptTree": {
"application/vnd.github.mockingbird-preview": [
"/repos/:owner/:repo/issues/:issue_number/timeline"
],

"application/vnd.github.spiderman-preview": [
"/repos/:owner/:repo/traffic/popular/referrers",
"/repos/:owner/:repo/traffic/popular/paths",
"/repos/:owner/:repo/traffic/views",
"/repos/:owner/:repo/traffic/clones"
],

"application/vnd.github.squirrel-girl-preview": [
"/repos/:owner/:repo/comments/:id/reactions",
"/repos/:owner/:repo/issues/:number/reactions",
"/repos/:owner/:repo/issues/comments/:id/reactions",
"/repos/:owner/:repo/pulls/comments/:id/reactions",
"/reactions/:id"
],

"application/vnd.github.polaris-preview": [
"/repos/:owner/:repo/pulls/:number/merge"
],

"application/vnd.github.loki-preview+json": [
"/repos/:owner/:repo/branches",
"/repos/:owner/:repo/branches/:branch",
"/repos/:owner/:repo/branches/:branch/protection"
],

"application/vnd.github.inertia-preview+json": [
"/repos/:owner/:repo/projects"
],

"application/vnd.github.mister-fantastic-preview+json": [
"/repos/:owner/:repo/pages",
"/repos/:owner/:repo/pages/builds"
],

"application/vnd.github.damage-preview": [
"/applications/grants",
"/applications/grants/:id",
"/authorizations/:id",
"/authorizations",
"/authorizations/clients/:client_id/:fingerprint",
"/applications/:client_id/tokens/:access_token"
],

"application/vnd.github.ant-man-preview+json": [
"/repos/:owner/:repo/deployments",
"/repos/:owner/:repo/deployments/:id/statuses"
],

"application/vnd.github.cryptographer-preview": [
"/user/gpg_keys",
"/user/gpg_keys/:id"
],

"application/vnd.github.barred-rock-preview": [
"/repos/:owner/:repo/import/authors",
"/repos/:owner/:repo/import/authors/:author_id",
"/:owner/:name/import/lfs",
"/:owner/:name/import/large_files",
"/repos/:owner/:repo/import"
],

"application/vnd.github.machine-man-preview": [
"/integration/installations",
"/installations/:installation_id/access_tokens",
"/integration/identity/user"
],

"application/vnd.github.drax-preview+json": [
"/licenses",
"/licenses/:license",
"/repos/:owner/:repo",
"/repos/:owner/:repo/license"
],

"application/vnd.github.wyandotte-preview+json": [
"/orgs/:org/migrations",
"/orgs/:org/migrations/:id",
"/orgs/:org/migrations/:id/archive",
"/orgs/:org/migrations/:id/repos/:repo_name/lock"
]
}
},

Expand Down

0 comments on commit 0704c0e

Please sign in to comment.