-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathHeaderUtil.java
61 lines (44 loc) · 1.38 KB
/
HeaderUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package util;
import java.util.HashMap;
import java.util.Map;
public class HeaderUtil {
public static String getUriInHeader(String header) {
String[] headerArr = header.split(" ");
return headerArr[1];
}
public static String getRealUrl(String url) {
int index = url.indexOf("?");
if (index == -1) {
return url;
}
return url.substring(0, index);
}
public static String getParamInUrl(String url) {
int index = url.indexOf("?");
if (index == -1) {
return "";
}
return url.substring(index+1);
}
public static Map<String, String> paramToMap(String paramText) {
int length = paramText.length();
String[] paramArr = paramText.split("&");
Map<String, String> paramMap = new HashMap<>();
if (length == 0) {
return paramMap;
}
for (String param : paramArr) {
mapInputParam(param, paramMap);
}
System.out.println(paramMap);
return paramMap;
}
private static void mapInputParam (String param, Map<String, String> paramMap) {
int index = param.indexOf("=");
if(index > -1) {
String key = param.substring(0, index);
String value = param.substring(index + 1, param.length());
paramMap.put(key, value);
}
}
}