Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit 3a44583

Browse files
committed
Correct parsing of Set-Cookie for arrays
1 parent 2d556d8 commit 3a44583

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [FIXED] Parsing of max-age from Set-Cookie headers.
3+
14
# 4.3.1 (2021-03-17)
25
- [NEW] Add migration guide to the newly supported cloudant-node-sdk
36
(package: @ibm-cloud/cloudant).

lib/tokens/TokenManager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2019 IBM Corp. All rights reserved.
1+
// Copyright © 2019, 2021 IBM Corp. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -32,7 +32,9 @@ class TokenManager {
3232
_autoRenew(defaultMaxAgeSecs) {
3333
debug('Auto renewing token now...');
3434
this._renew().then((response) => {
35-
let maxAgeSecs = cookie.parse(response.headers['set-cookie'][0])['Max-Age'] || defaultMaxAgeSecs;
35+
let setCookieHeader = response.headers['set-cookie'];
36+
let headerValue = Array.isArray(setCookieHeader) ? setCookieHeader[0] : setCookieHeader;
37+
let maxAgeSecs = cookie.parse(headerValue)['Max-Age'] || defaultMaxAgeSecs;
3638
let delayMSecs = maxAgeSecs / 2 * 1000;
3739
debug(`Renewing token in ${delayMSecs} milliseconds.`);
3840
setTimeout(this._autoRenew.bind(this, defaultMaxAgeSecs), delayMSecs).unref();

0 commit comments

Comments
 (0)