Commit fbeac25d authored by Robert Knight's avatar Robert Knight

Remove Hypothesis-Client-Version header from "trivial" API requests

Remove the custom headers from the `/api/` and `/api/links` API requests
so that we can preload these routes very early in the sidebar app's
startup process using `<link rel="preload">`, thus reducing the number
of roundtrips required before showing annotations.

The original motivations for adding this header (see [1]) don't really
apply to these trivial API requests but to ones which result in real
work on the backend.

For context, see https://hypothes-is.slack.com/archives/C4K6M7P5E/p1575447372326000.

[1] See https://github.com/hypothesis/client/pull/930.
parent e367b65b
......@@ -14,12 +14,11 @@ function apiRoutes(settings) {
let linkCache;
function getJSON(url) {
const config = {
headers: {
'Hypothesis-Client-Version': '__VERSION__', // replaced by versionify
},
};
return fetch(url, config).then(response => {
// nb. The `/api/` and `/api/links` routes are fetched without specifying
// any additional headers/config so that we can use `<link rel="preload">` in
// the `/app.html` response to fetch them early, while the client JS app
// is loading.
return fetch(url).then(response => {
if (response.status !== 200) {
throw new Error(`Fetching ${url} failed`);
}
......
......@@ -91,14 +91,6 @@ describe('sidebar.api-routes', () => {
assert.deepEqual(routes, apiIndexResponse.links);
});
});
it('sends client version custom request header', () => {
return apiRoutes.routes().then(() => {
assert.calledWith(window.fetch, fakeSettings.apiUrl, {
headers: { 'Hypothesis-Client-Version': '__VERSION__' },
});
});
});
});
describe('#links', () => {
......
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