mirror of
https://github.com/Wanxp/obsidian-douban.git
synced 2026-04-04 16:48:44 +08:00
add text to headers converter
This commit is contained in:
parent
3def97db92
commit
198cffaada
@ -23,6 +23,32 @@ export default class StringUtil {
|
|||||||
return id;
|
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 {
|
public static confuse(text: string):string {
|
||||||
if (!text) {
|
if (!text) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user