From b848368c8b5387c4171991126415b32f00c232d6 Mon Sep 17 00:00:00 2001 From: Eero af Heurlin Date: Wed, 29 Sep 2021 16:30:22 +0300 Subject: [PATCH] QnD basic auth support by parsing the username and password from the URL --- .../hyperlog/HLHTTPMultiPartPostRequest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hyperlog/src/main/java/com/hypertrack/hyperlog/HLHTTPMultiPartPostRequest.java b/hyperlog/src/main/java/com/hypertrack/hyperlog/HLHTTPMultiPartPostRequest.java index 5299b5d..394751f 100644 --- a/hyperlog/src/main/java/com/hypertrack/hyperlog/HLHTTPMultiPartPostRequest.java +++ b/hyperlog/src/main/java/com/hypertrack/hyperlog/HLHTTPMultiPartPostRequest.java @@ -167,6 +167,19 @@ public Map getHeaders() { //Header for file upload params.put("Content-Disposition", "attachment; filename=" + filename); + try { + URL url = new URL(this.getUrl()); + final String authority = url.getUserInfo(); + + if (authority != null) { + String auth = "Basic " + Base64.getEncoder().encodeToString(authority.getBytes()); + params.put("Authorization", auth); + } + } catch(Exception e) { + // FIXME: Do something saner with this + System.out.println("url parsing failure"); + } + if (mGzipEnabled) { params.put(HEADER_ENCODING, ENCODING_GZIP); } @@ -228,4 +241,4 @@ protected void deliverResponse(T response) { public String getBodyContentType() { return "multipart/form-data;boundary=" + boundary; } -} \ No newline at end of file +}