Skip to content

Commit 55a6837

Browse files
committed
If ther are multiple WWW-Authenticate lines, pick Digest over Basic. (Seen on my really old HikVision camera)
1 parent 700e8ba commit 55a6837

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

lib/RTSPClient.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,30 @@ export default class RTSPClient extends EventEmitter {
908908
const key = line.substring(0, indexOf).trim();
909909
const data = line.substring(indexOf + 1).trim();
910910

911-
this.rtspHeaders[key] =
912-
key != "Session" && data.match(/^[0-9]+$/)
911+
if (key == "Session") this.rtspHeaders[key] = data;
912+
913+
else if (key == "WWW-Authenticate") {
914+
// Handle multiple WWW-Authenticate entries and pick the 'best'
915+
// We prefer 'Digest' over 'Basic'
916+
// We preger 'Digest SHAxxx' over 'Digest MD5' or 'Digest with no algorithm (defaults to MD5) (STILL TODO)
917+
if (key in this.rtspHeaders) {
918+
console.log("Duplicate WWW-Authenticate keys")
919+
if (data.startsWith("Digest") && this.rtspHeaders[key]?.startsWith("Basic")) {
920+
this.rtspHeaders[key] = data; // Replace Basic with Digest
921+
}
922+
console.log("Keeping WWW-Authenticate: " + this.rtspHeaders[key]);
923+
} else {
924+
this.rtspHeaders[key] = data;
925+
}
926+
}
927+
928+
else {
929+
// Store the result as either a String type or a Number type
930+
this.rtspHeaders[key] =
931+
data.match(/^[0-9]+$/)
913932
? parseInt(data, 10)
914933
: data;
934+
}
915935

916936
// workaround for buggy Hipcam RealServer/V1.0 camera which returns Content-length and not Content-Length
917937
if (key.toLowerCase() == "content-length") {

0 commit comments

Comments
 (0)