Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/185#discussion_r17905675
  
    --- Diff: core/src/main/java/brooklyn/util/ResourceUtils.java ---
    @@ -388,6 +403,43 @@ public void close() throws IOException {
             }
         }
         
    +    //For HTTP(S) targets use HttpClient so
    +    //we can do authentication
    +    private InputStream getResourceViaHttp(String url) throws IOException {
    +        HttpClientBuilder builder = HttpTool.httpClientBuilder()
    +                .laxRedirect(true)
    +                .uri(url);
    +        Credentials credentials = getUrlCredentials(url);
    +        if (credentials != null) {
    +            builder.credentials(credentials);
    +        }
    +        HttpClient client = builder.build();
    +        HttpResponse result = client.execute(new HttpGet(url));
    +        int statusCode = result.getStatusLine().getStatusCode();
    +        if (HttpTool.isStatusCodeHealthy(statusCode)) {
    +            HttpEntity entity = result.getEntity();
    +            if (entity != null) {
    +                return entity.getContent();
    +            } else {
    +                return new ByteArrayInputStream(new byte[0]);
    +            }
    +        } else {
    +            EntityUtils.consume(result.getEntity());
    +            throw new IllegalStateException("Invalid response invoking " + 
url + ": response code " + statusCode);
    +        }
    +    }
    +
    +    private Credentials getUrlCredentials(String url) {
    +        Matcher m = AUTH_URL.matcher(url);
    +        if (m.matches() && m.groupCount() == 3) {
    +            String username = m.group(1);
    --- End diff --
    
    do `username` and `password` need to be url unescaped?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to