mirror of
https://github.com/rapid7/metasploit-payloads
synced 2024-12-02 20:36:40 +01:00
add shared code for addrequestheader
This commit is contained in:
parent
a63b17249b
commit
0f8419e05c
@ -0,0 +1,27 @@
|
||||
package com.metasploit.stage;
|
||||
|
||||
import java.net.URLConnection;
|
||||
|
||||
public class HttpConnection {
|
||||
|
||||
private static boolean isEmpty(String string) {
|
||||
return (string == null || "".equals(string));
|
||||
}
|
||||
|
||||
public static void addRequestHeaders(URLConnection connection, String headers, String userAgent) {
|
||||
if (!isEmpty(userAgent)) {
|
||||
connection.addRequestProperty("User-Agent", userAgent);
|
||||
}
|
||||
String[] headerPairs = headers.split("\r\n");
|
||||
for (String header : headerPairs) {
|
||||
if (isEmpty(header)) {
|
||||
continue;
|
||||
}
|
||||
String[] headerPair = header.split(": ", 2);
|
||||
if (headerPair.length == 2 && !isEmpty(headerPair[0]) && !isEmpty(headerPair[1])) {
|
||||
connection.addRequestProperty(headerPair[0], headerPair[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user