diff --git a/README.md b/README.md index fba038b..50727aa 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,9 @@ You can set all the following variables: * `PLANTUML_STATS` * Set it to `on` to enable [statistics report](http://plantuml.com/statistics-report) * Default value `off` - +* `HTTP_AUTHORIZATION` + * when calling the `proxy` endpoint, the value of `HTTP_AUTHORIZATION` will be used to set the HTTP Authorization header + * Default value: null Alternate: How to build your docker image diff --git a/src/main/java/net/sourceforge/plantuml/servlet/ProxyServlet.java b/src/main/java/net/sourceforge/plantuml/servlet/ProxyServlet.java index c124122..979abde 100644 --- a/src/main/java/net/sourceforge/plantuml/servlet/ProxyServlet.java +++ b/src/main/java/net/sourceforge/plantuml/servlet/ProxyServlet.java @@ -135,20 +135,18 @@ public class ProxyServlet extends HttpServlet { } private HttpURLConnection getConnection(final URL url) throws IOException { - if (url.getProtocol().startsWith("https")) { - HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); - con.setRequestMethod("GET"); - con.setReadTimeout(10000); // 10 seconds - // printHttpsCert(con); - con.connect(); - return con; - } else { - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setRequestMethod("GET"); - con.setReadTimeout(10000); // 10 seconds - con.connect(); - return con; + final HttpURLConnection con = (HttpURLConnection) url.openConnection(); + if (con instanceof HttpsURLConnection) { + // printHttpsCert((HttpsURLConnection) con); } + con.setRequestMethod("GET"); + String token = System.getenv("HTTP_AUTHORIZATION"); + if (token != null) { + con.setRequestProperty("Authorization", token); + } + con.setReadTimeout(10000); // 10 seconds + con.connect(); + return con; } /**