kaven-utils
Version:
Utils for Node.js.
42 lines (41 loc) • 1.26 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: 2025-10-14 22:58:04.868
* @version: 6.1.0
* @times: 10
* @lines: 50
* @copyright: Copyright © 2022-2025 Kaven. All Rights Reserved.
* @description: [description]
* @license: [license]
********************************************************************/
import { TrimStart } from "kaven-basic";
export class HttpHeader {
Logger;
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) {
this.Logger?.Warn(`Invalid Http Header: ${line}`);
this.Value = "";
return false;
}
else {
// Whitespace before the value is ignored.
this.Value = TrimStart(line, this.Name + ":").trimStart();
}
return true;
}
}