1
1
package burp ;
2
+
2
3
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
- */
8
4
import java .net .URL ;
9
5
import java .util .ArrayList ;
10
6
import java .util .Arrays ;
11
7
import java .util .LinkedHashMap ;
12
8
import java .util .List ;
13
9
import java .util .Map .Entry ;
14
10
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
+
15
17
public class Getter {
16
18
private static IExtensionHelpers helpers ;
17
19
private final static String Header_Spliter = ":" ;
@@ -35,7 +37,7 @@ public List<String> getHeaderList(boolean messageIsRequest,IHttpRequestResponse
35
37
}
36
38
return getHeaderList (messageIsRequest ,requestOrResponse );
37
39
}
38
-
40
+
39
41
/*
40
42
* 获取请求包或者响应包中的header List
41
43
*/
@@ -198,57 +200,92 @@ public byte[] getBody(boolean isRequest,byte[] requestOrResponse) {
198
200
* this return value of url contains default port, 80 :443
199
201
* eg. http://bit4woo.com:80/
200
202
*/
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
+ }
206
211
}
207
212
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
-
219
213
/*
220
214
*
221
215
* this return value of url will NOT contains default port, 80 :443
222
216
* eg. https://www.baidu.com
223
217
*/
224
- public String getShortUrl (IHttpRequestResponse messageInfo ) {
218
+ public String getShortUrlStringWithoutDefaultPort (IHttpRequestResponse messageInfo ) {
225
219
return messageInfo .getHttpService ().toString (); //this result of this method doesn't contains default port
226
220
}
227
221
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
+
228
233
/*
229
- * this return value of url will NOT contains default port, 80 :443
234
+ *
230
235
*/
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 {
236
241
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
+ }
238
248
} catch (MalformedURLException e ) {
239
249
e .printStackTrace ();
240
250
}
251
+ return null ;
241
252
}
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 ;
248
268
}
249
- return url ;
250
269
}
251
270
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
+
252
289
public String getHost (IHttpRequestResponse messageInfo ) {
253
290
return messageInfo .getHttpService ().getHost ();
254
291
}
0 commit comments