Skip to content

Commit

Permalink
Merge pull request #9 from lmontoute/patch-1
Browse files Browse the repository at this point in the history
Fix Authorization header
  • Loading branch information
haeric authored Nov 17, 2017
2 parents fce9a9b + d06a0f1 commit b6334d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export class Request {
xhr.setRequestHeader('Accept', 'application/json')
}

if(this.auth === 'string') {
if(this.auth && typeof this.auth === 'string') {
xhr.setRequestHeader('Authorization', this.auth);
}

Expand Down
13 changes: 13 additions & 0 deletions src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ test('failure retries, then rejects promise', (t : any) => {
let request = requests.queue[0]
})

test('authorization header', (t : any) => {
t.plan(1)
const requests = new RequestQueue()
requests.get(`${TEST_URL}/headers`, {
auth: 'Test auth',
responseType: 'json'
}).then((response) => {
t.equal(response.headers.Authorization, 'Test auth')
}).catch(() => {
t.fail('Request failed')
})
})

test('arraybuffer responseType', (t : any) => {
t.plan(2)
const requests = new RequestQueue()
Expand Down

0 comments on commit b6334d2

Please sign in to comment.