Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
96d55c90
Unverified
Commit
96d55c90
authored
Feb 11, 2019
by
Robert Knight
Committed by
GitHub
Feb 11, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #930 from hypothesis/add-client-version-header-to-api-requests
Add custom client version header to api requests
parents
158b7680
66067d72
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
2 deletions
+29
-2
api-routes.js
src/sidebar/services/api-routes.js
+6
-1
api.js
src/sidebar/services/api.js
+3
-1
api-routes-test.js
src/sidebar/services/test/api-routes-test.js
+8
-0
api-test.js
src/sidebar/services/test/api-test.js
+12
-0
No files found.
src/sidebar/services/api-routes.js
View file @
96d55c90
...
...
@@ -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`
);
}
...
...
src/sidebar/services/api.js
View file @
96d55c90
...
...
@@ -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
)
{
...
...
src/sidebar/services/test/api-routes-test.js
View file @
96d55c90
...
...
@@ -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'
,
()
=>
{
...
...
src/sidebar/services/test/api-test.js
View file @
96d55c90
...
...
@@ -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
();
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment