add text to headers converter

This commit is contained in:
wanxp 2023-09-19 15:12:53 +08:00
parent 3def97db92
commit 198cffaada

@ -23,6 +23,32 @@ export default class StringUtil {
return id;
}
/**
* request headers json
* @param text
* @return json object
*/
public static parseHeaders(text: string): any {
let headers = {};
if (text) {
//如果首行包含'GET'或者'POST',则去掉首行
if (text.indexOf('GET') == 0 || text.indexOf('POST') == 0) {
text = text.substring(text.indexOf('\n') + 1);
}
let lines = text.split('\n');
for (let line of lines) {
let index = line.indexOf(':');
if (index > 0) {
let key = line.substring(0, index);
let value = line.substring(index + 1).trim();
// @ts-ignore
headers[key] = value;
}
}
}
return headers;
}
public static confuse(text: string):string {
if (!text) {