Skip to content

Bug in httpClientHelper when proxy is used #1274

Open
@thboileau

Description

@thboileau

Reported by Jean-Christophe Malapert.

I use the restlet version 2.3.10 and org.restlet.ext.httpclient extension.
Each request passes through a proxy.

Engine.getInstance().getRegisteredClients().clear();
Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));
this.client = new ClientResource(uri);
Client proxy = new Client(new Context(), Arrays.asList(Protocol.HTTP, Protocol.HTTPS));
proxy.getContext().getParameters().add("proxyHost", host);
proxy.getContext().getParameters().add("proxyPort", port);               
this.client.setProxyChallengeResponse(ChallengeScheme.HTTP_BASIC, login, pwd);
this.client.setNext(proxy);

Restlet works perfectly when I want to query an URL using HTTP protocol but there is a problem
when I want to query an URL using HTTPS protocol. I seems that the credentials are not send
to the proxy when the target uses the HTTPS protocol.

If I write a simple code with the last version of httpclient, I can pass my proxy :

CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
                new AuthScope("SERVER_PROXY_HOST", 1234),
                new UsernamePasswordCredentials("login", "password")
        );
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();

int status = 0;
try {
    //HttpHost target = new HttpHost("www.google.fr", 443, "https");
    HttpHost proxy = new HttpHost("SERVER_PROXY_HOST", 1234, "http");            
   
    RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
    HttpGet request = new HttpGet("https://www.google.fr");
    request.setConfig(config);                        
    
    System.out.println("Executing request " + request.getRequestLine()+" to "+ request.getURI() +" via "+proxy);
    CloseableHttpResponse response = httpclient.execute(request);
    status = response.getStatusLine().getStatusCode();
    try {
        System.out.println("--------");
        System.out.println(response.getStatusLine());
        System.out.println(EntityUtils.toString(response.getEntity()));
    } finally {
        response.close();
    }
    
} finally {
    httpclient.close();
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions