Unverified Commit 96d55c90 authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #930 from hypothesis/add-client-version-header-to-api-requests

Add custom client version header to api requests
parents 158b7680 66067d72
......@@ -14,7 +14,12 @@ function apiRoutes($http, settings) {
let linkCache;
function getJSON(url) {
return $http.get(url).then(({ status, data }) => {
const config = {
headers: {
'Hypothesis-Client-Version': '__VERSION__', // replaced by versionify
},
};
return $http.get(url, config).then(({ status, data }) => {
if (status !== 200) {
throw new Error(`Fetching ${url} failed`);
}
......
......@@ -143,7 +143,9 @@ function createAPICall($http, $q, links, route, tokenGetter) {
.then(([links, token]) => {
const descriptor = get(links, route);
const url = urlUtil.replaceURLParams(descriptor.url, params);
const headers = {};
const headers = {
'Hypothesis-Client-Version': '__VERSION__', // replaced by versionify
};
accessToken = token;
if (token) {
......
......@@ -89,6 +89,14 @@ describe('sidebar.api-routes', () => {
assert.deepEqual(routes, apiIndexResponse.links);
});
});
it('sends client version custom request header', () => {
return apiRoutes.routes().then(() => {
assert.calledWith(fakeHttp.get, fakeSettings.apiUrl, {
headers: { 'Hypothesis-Client-Version': '__VERSION__' },
});
});
});
});
describe('#links', () => {
......
......@@ -364,4 +364,16 @@ describe('sidebar.services.api', function() {
.respond(() => [200, { userid: 'acct:user@example.com' }]);
$httpBackend.flush();
});
it('sends client version custom request header', () => {
api.profile.read({});
$httpBackend
.expectGET(
'https://example.com/api/profile',
headers => headers['Hypothesis-Client-Version'] === '__VERSION__'
)
.respond(() => [200, { userid: 'acct:user@example.com' }]);
$httpBackend.flush();
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment