Skip to content

Commit

Permalink
Merge pull request #160 from alexpogue/safeheaders
Browse files Browse the repository at this point in the history
Add defensive code behind extraHeaders
  • Loading branch information
ddebrunner committed Sep 17, 2015
2 parents 4549349 + 3e90dde commit 7602976
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;

Expand All @@ -31,8 +33,13 @@
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.BasicClientConnectionManager;

import com.ibm.streams.operator.logging.TraceLevel;

public class HTTPUtils {

static final String CLASS_NAME="com.ibm.streamsx.inet.http.HTTPUtils";
private static Logger trace = Logger.getLogger(CLASS_NAME);

public static HttpURLConnection getNewConnection(String url)
throws IOException {
return (HttpURLConnection)new URL(url).openConnection();
Expand All @@ -59,9 +66,14 @@ public static String readFromStream(InputStream stream) {
}

public static Map<String, String> getHeaderMap(List<String> headers) {
if(headers == null) return Collections.emptyMap();
Map<String, String> headerMap = new HashMap<String, String>(headers.size());
for(String header : headers) {
String[] headerParts = header.split(":\\s*", 2);
if(headerParts.length < 2) {
trace.log(TraceLevel.ERROR, "No ':' found in extraHeaders element '" + header + "', skipping");
continue;
}
String headerName = headerParts[0];
String headerValue = headerParts[1];
headerMap.put(headerName, headerValue);
Expand Down

0 comments on commit 7602976

Please sign in to comment.