Skip to content

Commit 325b52c

Browse files
committed
Update Getter.java
更新各种URL获取方法
1 parent 42c6dec commit 325b52c

File tree

1 file changed

+74
-37
lines changed

1 file changed

+74
-37
lines changed

src/main/java/burp/Getter.java

Lines changed: 74 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package burp;
2+
23
import java.net.MalformedURLException;
3-
/*
4-
* source code: https://github.com/bit4woo/burp-api-common/blob/master/src/main/java/burp/Getter.java
5-
* author: bit4woo
6-
* github: https://github.com/bit4woo
7-
*/
84
import java.net.URL;
95
import java.util.ArrayList;
106
import java.util.Arrays;
117
import java.util.LinkedHashMap;
128
import java.util.List;
139
import java.util.Map.Entry;
1410

11+
/*
12+
* source code: https://github.com/bit4woo/burp-api-common/blob/master/src/main/java/burp/Getter.java
13+
* author: bit4woo
14+
* github: https://github.com/bit4woo
15+
*/
16+
1517
public class Getter {
1618
private static IExtensionHelpers helpers;
1719
private final static String Header_Spliter = ":";
@@ -35,7 +37,7 @@ public List<String> getHeaderList(boolean messageIsRequest,IHttpRequestResponse
3537
}
3638
return getHeaderList(messageIsRequest,requestOrResponse);
3739
}
38-
40+
3941
/*
4042
* 获取请求包或者响应包中的header List
4143
*/
@@ -198,57 +200,92 @@ public byte[] getBody(boolean isRequest,byte[] requestOrResponse) {
198200
* this return value of url contains default port, 80 :443
199201
* eg. http://bit4woo.com:80/
200202
*/
201-
public String getShortUrlWithDefaultPort(IHttpRequestResponse messageInfo) {
202-
//return messageInfo.getHttpService().toString(); //this result of this method doesn't contains default port
203-
URL fullUrl = getURLWithDefaultPort(messageInfo);
204-
String shortUrl = fullUrl.toString().replace(fullUrl.getFile(), "/");
205-
return shortUrl;
203+
public String getShortUrlStringWithDefaultPort(IHttpRequestResponse messageInfo) {
204+
URL fullUrl = getFullURLWithDefaultPort(messageInfo);
205+
if (fullUrl == null) {
206+
return null;
207+
}else {
208+
String shortUrl = fullUrl.toString().replace(fullUrl.getFile(), "/");
209+
return shortUrl;
210+
}
206211
}
207212

208-
/*
209-
* 注意,这里获取的URL包含了默认端口!
210-
* this return value of url contains default port, 80 :443
211-
* eg. http://bit4woo.com:80/
212-
*/
213-
public URL getURLWithDefaultPort(IHttpRequestResponse messageInfo){
214-
if (null == messageInfo) return null;
215-
IRequestInfo analyzeRequest = helpers.analyzeRequest(messageInfo);
216-
return analyzeRequest.getUrl();
217-
}
218-
219213
/*
220214
*
221215
* this return value of url will NOT contains default port, 80 :443
222216
* eg. https://www.baidu.com
223217
*/
224-
public String getShortUrl(IHttpRequestResponse messageInfo) {
218+
public String getShortUrlStringWithoutDefaultPort(IHttpRequestResponse messageInfo) {
225219
return messageInfo.getHttpService().toString(); //this result of this method doesn't contains default port
226220
}
227221

222+
223+
public String getFullUrlStringWithDefaultPort(IHttpRequestResponse messageInfo) {
224+
225+
URL fullUrl = getFullURLWithDefaultPort(messageInfo);
226+
if (fullUrl == null) {
227+
return null;
228+
}else {
229+
return fullUrl.toString();
230+
}
231+
}
232+
228233
/*
229-
* this return value of url will NOT contains default port, 80 :443
234+
*
230235
*/
231-
public URL getURL(IHttpRequestResponse messageInfo){
232-
if (null == messageInfo) return null;
233-
IRequestInfo analyzeRequest = helpers.analyzeRequest(messageInfo);
234-
URL url = analyzeRequest.getUrl();
235-
if (url.getProtocol().equalsIgnoreCase("https") && url.getPort() == 443) {
236+
public String getFullUrlStringWithoutDefaultPort(IHttpRequestResponse messageInfo) {
237+
URL fullUrl = getFullURLWithDefaultPort(messageInfo);
238+
if (fullUrl == null) {
239+
return null;
240+
}else {
236241
try {
237-
return new URL(url.toString().replaceFirst(":443/", ":/"));
242+
if (fullUrl.getProtocol().equalsIgnoreCase("https") && fullUrl.getPort() == 443) {
243+
return new URL(fullUrl.toString().replaceFirst(":443/", ":/")).toString();
244+
}
245+
if (fullUrl.getProtocol().equalsIgnoreCase("http") && fullUrl.getPort() == 80) {
246+
return new URL(fullUrl.toString().replaceFirst(":80/", ":/")).toString();
247+
}
238248
} catch (MalformedURLException e) {
239249
e.printStackTrace();
240250
}
251+
return null;
241252
}
242-
if (url.getProtocol().equalsIgnoreCase("http") && url.getPort() == 80) {
243-
try {
244-
return new URL(url.toString().replaceFirst(":80/", ":/"));
245-
} catch (MalformedURLException e) {
246-
e.printStackTrace();
247-
}
253+
}
254+
255+
/*
256+
* return Type is URL,not String.
257+
* use equal() function to compare URL object. the string contains default port or not both OK
258+
* URL对象可以用它自己提供的equal()函数进行对比,是否包含默认端口都是没有关系的。
259+
*/
260+
public URL getShortURL(IHttpRequestResponse messageInfo){
261+
if (null == messageInfo) return null;
262+
String shortUrlString = messageInfo.getHttpService().toString();
263+
try {
264+
return new URL(shortUrlString);
265+
} catch (MalformedURLException e) {
266+
e.printStackTrace();
267+
return null;
248268
}
249-
return url;
250269
}
251270

271+
/*
272+
* return Type is URL,not String.
273+
* use equal() function to compare URL object. the string contains default port or not both OK
274+
* URL对象可以用它自己提供的equal()函数进行对比,是否包含默认端口都是没有关系的。
275+
*
276+
* 但这个函数的返回结果转换成字符串是包含了默认端口的。
277+
*/
278+
public final URL getFullURL(IHttpRequestResponse messageInfo){
279+
if (null == messageInfo) return null;
280+
IRequestInfo analyzeRequest = helpers.analyzeRequest(messageInfo);
281+
return analyzeRequest.getUrl();
282+
}
283+
284+
private final URL getFullURLWithDefaultPort(IHttpRequestResponse messageInfo){
285+
return getFullURL(messageInfo);
286+
}
287+
288+
252289
public String getHost(IHttpRequestResponse messageInfo) {
253290
return messageInfo.getHttpService().getHost();
254291
}

0 commit comments

Comments
 (0)