Skip to content

Commit

Permalink
更稳定的解析request header的键值
Browse files Browse the repository at this point in the history
  • Loading branch information
c0ny1 committed Dec 19, 2019
1 parent 955afaf commit 5737d11
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/main/java/utils/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import burp.IHttpRequestResponse;
import burp.IRequestInfo;
import entity.HttpService;

import java.io.BufferedOutputStream;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -111,12 +113,11 @@ private void parserRequest(){
continue;
}

if (header.indexOf(": ") > 0) {
String key = header.split(": ")[0];
String value = header.split(": ")[1];
if (header.indexOf(":") > 0) {
String key = header.substring(0, header.indexOf(":"));
String value = Util.trimStart(header.substring(header.indexOf(":")+1, header.length()));
this.headers.put(key, value);
}
System.out.println(header);
}

if (this.method.equals("POST")) {
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/utils/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,28 @@ public static String matchByRegular(String str,String reg,int n){
return res;
}

/**
* 将字符串开头空格去掉
* @param str
* @return
*/
public static String trimStart(String str) {
if (str == "" || str == null) {
return str;
}


final char[] value = str.toCharArray();
int start = 0, last = 0 + str.length() - 1;
int end = last;
while ((start <= end) && (value[start] <= ' ')) {
start++;
}
if (start == 0 && end == last) {
return str;
}
if (start >= end) {
return "";
}
return str.substring(start, end);
}
}

0 comments on commit 5737d11

Please sign in to comment.