From 1bdd2482ba5188c5f36a20a1fadbbb2a18ca50f4 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Tue, 31 Mar 2020 21:37:05 -0400 Subject: [PATCH] add HttpUtil.get that takes two sets of headers --- .../java/org/cobbzilla/util/http/HttpUtil.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/cobbzilla/util/http/HttpUtil.java b/src/main/java/org/cobbzilla/util/http/HttpUtil.java index 62689dc..8f81b1c 100644 --- a/src/main/java/org/cobbzilla/util/http/HttpUtil.java +++ b/src/main/java/org/cobbzilla/util/http/HttpUtil.java @@ -69,16 +69,23 @@ public class HttpUtil { public static InputStream get (String urlString) throws IOException { return get(urlString, null); } public static InputStream get (String urlString, Map headers) throws IOException { + return get(urlString, headers, null); + } + + public static InputStream get (String urlString, Map headers, Map headers2) throws IOException { final URL url = new URL(urlString); final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); - if (headers != null) { - for (Map.Entry h : headers.entrySet()) { - urlConnection.setRequestProperty(h.getKey(), h.getValue()); - } - } + if (headers != null) addHeaders(urlConnection, headers); + if (headers2 != null) addHeaders(urlConnection, headers2); return urlConnection.getInputStream(); } + public static void addHeaders(HttpURLConnection urlConnection, Map headers) { + for (Map.Entry h : headers.entrySet()) { + urlConnection.setRequestProperty(h.getKey(), h.getValue()); + } + } + public static HttpResponseBean upload (String url, File file, Map headers) throws IOException {