mirror of
https://github.com/certd/certd.git
synced 2026-04-19 00:50:53 +08:00
76 lines
1.9 KiB
TypeScript
76 lines
1.9 KiB
TypeScript
import { Constant } from '../common/Constant.js'; // Assuming you have a TypeScript version of this
|
|
|
|
export class HttpRequestMsg {
|
|
uri: string ;
|
|
url: string;
|
|
host: string;
|
|
method: string;
|
|
protocol: string;
|
|
params: Record<string, string>;
|
|
headers: Record<string, string>;
|
|
body: string;
|
|
signedHeaders: string;
|
|
msg: any;
|
|
|
|
constructor() {
|
|
this.params = {};
|
|
this.headers = {};
|
|
this.putHeader('Content-Type', Constant.APPLICATION_JSON);
|
|
this.putHeader(Constant.X_CNC_AUTH_METHOD, Constant.AUTH_METHOD);
|
|
}
|
|
|
|
putParam(name: string, value: string): void {
|
|
this.params[name] = value;
|
|
}
|
|
|
|
getParam(name: string): string | null {
|
|
const value = this.params[name];
|
|
return value && value.trim() !== '' ? value : null;
|
|
}
|
|
|
|
getQueryString(): string {
|
|
if(this.uri == undefined)
|
|
return "";
|
|
const index = this.uri.indexOf("?");
|
|
if (this.method === 'POST' || index === -1) {
|
|
return "";
|
|
}
|
|
return this.uri.substring(index + 1);
|
|
}
|
|
|
|
putHeader(name: string, value: string): void {
|
|
this.headers[name] = value;
|
|
}
|
|
|
|
getHeader(name: string): string | null {
|
|
for (const key in this.headers) {
|
|
if (key.toLowerCase() === name.toLowerCase()) {
|
|
return this.headers[key];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
getHeaderByNames(...names: string[]): string | null {
|
|
for (const name of names) {
|
|
const value = this.getHeader(name);
|
|
if (value) {
|
|
return value;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
removeHeader(name: string): void {
|
|
for (const key in this.headers) {
|
|
if (key.toLowerCase() === name.toLowerCase()) {
|
|
delete this.headers[key];
|
|
}
|
|
}
|
|
}
|
|
|
|
setJsonBody(object: any): void {
|
|
this.body = JSON.stringify(object);
|
|
}
|
|
}
|