kaven-utils
Version:
Utils for Node.js.
41 lines (40 loc) • 1.27 kB
JavaScript
/********************************************************************
* @author: Kaven
* @email: kaven@wuwenkai.com
* @website: http://blog.kaven.xyz
* @file: [Kaven-Utils] /src/net/http/HttpHeader.ts
* @create: 2022-04-19 14:26:24.132
* @modify: 2023-12-07 10:59:05.563
* @version: 5.4.0
* @times: 6
* @lines: 49
* @copyright: Copyright © 2022-2023 Kaven. All Rights Reserved.
* @description: [description]
* @license: [license]
********************************************************************/
import { InternalLogger } from "../../KavenUtility.Internal.js";
export class HttpHeader {
constructor(name, value) {
this.Name = name;
this.Value = value;
}
Name;
Value;
ToString() {
return `${this.Name}: ${this.Value}`;
}
Parse(line) {
const parts = line.split(":");
this.Name = parts[0];
if (parts.length === 1) {
InternalLogger()?.Warn(`Invalid Http Header: ${line}`);
this.Value = "";
return false;
}
else {
// Whitespace before the value is ignored.
this.Value = line.TrimStart(this.Name + ":").trimStart();
}
return true;
}
}