Re: Strange behaviour when using Proxy

2018-12-15 Thread Philippe Mouawad
Hello,
Thanks .
Done:
https://issues.apache.org/jira/browse/HTTPCLIENT-1956

Regards

On Sat, Dec 15, 2018 at 9:54 PM Oleg Kalnichevski  wrote:

> On Sat, 2018-12-15 at 15:26 +0100, Philippe Mouawad wrote:
> > Hello,
> > I can create a github project but is it worth just for this  ?
> > I have reworked the test case to try to be more clear.
> >
> > Let me reformulate the problem related to this bug report on jmeter:
> >
> >- https://bz.apache.org/bugzilla/show_bug.cgi?id=62852
> >
>
> Please raise a JIRA for this defect.
>
> Oleg
>
> > The problem is that below method behaves differently if request is
> > emitted
> > directly or through a Proxy:
> >
> >- localContext.getAttribute(HttpCoreContext.HTTP_REQUEST);
> >
> > If you run code below and inspect:
> >
> >- localContext.getAttribute(HttpCoreContext.HTTP_REQUEST);
> >
> > While you  should get this (and you indeed get this if you don't use
> > a
> > proxy):
> >
> >- The GET method
> >- All headers:
> >   - X-Sleep:5
> >   - Host: jmeter.apache.org:443,
> >   - User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_161)
> >
> > Instead you get:
> >
> >- CONNECT method (the proxy related one)
> >- Partial Headers:
> >   - Host: jmeter.apache.org:443,
> >   - User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_161)
> >
> > In test case below:
> >
> >- http://localhost: act as proxy (you can use JMeter HTTP Test
> >Script recorder to start a proxy or any proxy implementation
> > running on
> >that port)
> >- https://jmeter.apache.org is the target website, but you can use
> > any
> >site you want
> >- X-Sleep is the custom header that is lost for example
> >
> > ---
> > 
> >package org.apache.jmeter.protocol.http.proxy;
> >
> > import java.util.Arrays;
> >
> > import javax.net.ssl.SSLContext;
> >
> > import org.apache.http.HttpHost;
> > import org.apache.http.HttpRequest;
> > import org.apache.http.client.config.RequestConfig;
> > import org.apache.http.client.methods.CloseableHttpResponse;
> > import org.apache.http.client.methods.HttpGet;
> > import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
> > import org.apache.http.conn.ssl.TrustAllStrategy;
> > import org.apache.http.impl.client.CloseableHttpClient;
> > import org.apache.http.impl.client.HttpClients;
> > import org.apache.http.protocol.BasicHttpContext;
> > import org.apache.http.protocol.HttpContext;
> > import org.apache.http.protocol.HttpCoreContext;
> > import org.apache.http.ssl.SSLContextBuilder;
> > import org.apache.http.ssl.TrustStrategy;
> > import org.hamcrest.CoreMatchers;
> > import org.junit.Assert;
> > import org.junit.Test;
> >
> > public class ProxyBug {
> >
> >
> > @Test
> > public void bugWithRequestThroughProxy() throws Exception {
> > TrustStrategy trustStrategy = new TrustAllStrategy();
> > SSLContext sslContext = new
> > SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build();
> > SSLConnectionSocketFactory socketFactory = new
> > SSLConnectionSocketFactory(sslContext);
> > CloseableHttpClient httpclient =
> > HttpClients.custom().setSSLSocketFactory(socketFactory).build();
> > try {
> >
> > HttpHost target = new HttpHost("jmeter.apache.org", 443,
> > "https");
> > HttpHost proxy = new HttpHost("localhost", , "http");
> >
> > RequestConfig config =
> > RequestConfig.custom().setProxy(proxy).build();
> > HttpGet request = new HttpGet("/");
> > request.addHeader("X-sleep", "5");
> > request.setConfig(config);
> >
> > HttpContext localContext = new BasicHttpContext();
> > CloseableHttpResponse response =
> > httpclient.execute(target,
> > request, localContext);
> > final HttpRequest httpRequestFromLocalContext =
> > (HttpRequest)
> > localContext
> > .getAttribute(HttpCoreContext.HTTP_REQUEST);
> > try {
> >
> > Assert.assertThat(httpRequestFromLocalContext.getRequestLine().getMet
> > hod(),
> > CoreMatchers.is("GET"));
> > Assert.assertThat(response.getStatusLine().getStatusC
> > ode(),
> > CoreMatchers.is(200));
> >
> > Assert.assertThat(Arrays.asList(request.getAllHeaders()).toString(),
> > CoreMatchers.containsString("X-sleep"));
> >
> > Assert.assertThat(Arrays.asList(httpRequestFromLocalContext.getAllHea
> > ders()).toString(),
> > CoreMatchers.containsString("X-sleep"));
> >
> > } finally {
> > response.close();
> > }
> > } finally {
> > httpclient.close();
> > }
> > }
> >
> > @Test
> > public void noBugWithDirectRequest() throws Exception {
> > TrustStrategy trustStrategy = new TrustAllStrategy();
> > SSLContext sslContext = new
> > 

Re: Strange behaviour when using Proxy

2018-12-15 Thread Oleg Kalnichevski
On Sat, 2018-12-15 at 15:26 +0100, Philippe Mouawad wrote:
> Hello,
> I can create a github project but is it worth just for this  ?
> I have reworked the test case to try to be more clear.
> 
> Let me reformulate the problem related to this bug report on jmeter:
> 
>- https://bz.apache.org/bugzilla/show_bug.cgi?id=62852
> 

Please raise a JIRA for this defect.

Oleg

> The problem is that below method behaves differently if request is
> emitted
> directly or through a Proxy:
> 
>- localContext.getAttribute(HttpCoreContext.HTTP_REQUEST);
> 
> If you run code below and inspect:
> 
>- localContext.getAttribute(HttpCoreContext.HTTP_REQUEST);
> 
> While you  should get this (and you indeed get this if you don't use
> a
> proxy):
> 
>- The GET method
>- All headers:
>   - X-Sleep:5
>   - Host: jmeter.apache.org:443,
>   - User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_161)
> 
> Instead you get:
> 
>- CONNECT method (the proxy related one)
>- Partial Headers:
>   - Host: jmeter.apache.org:443,
>   - User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_161)
> 
> In test case below:
> 
>- http://localhost: act as proxy (you can use JMeter HTTP Test
>Script recorder to start a proxy or any proxy implementation
> running on
>that port)
>- https://jmeter.apache.org is the target website, but you can use
> any
>site you want
>- X-Sleep is the custom header that is lost for example
> 
> ---
> 
>package org.apache.jmeter.protocol.http.proxy;
> 
> import java.util.Arrays;
> 
> import javax.net.ssl.SSLContext;
> 
> import org.apache.http.HttpHost;
> import org.apache.http.HttpRequest;
> import org.apache.http.client.config.RequestConfig;
> import org.apache.http.client.methods.CloseableHttpResponse;
> import org.apache.http.client.methods.HttpGet;
> import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
> import org.apache.http.conn.ssl.TrustAllStrategy;
> import org.apache.http.impl.client.CloseableHttpClient;
> import org.apache.http.impl.client.HttpClients;
> import org.apache.http.protocol.BasicHttpContext;
> import org.apache.http.protocol.HttpContext;
> import org.apache.http.protocol.HttpCoreContext;
> import org.apache.http.ssl.SSLContextBuilder;
> import org.apache.http.ssl.TrustStrategy;
> import org.hamcrest.CoreMatchers;
> import org.junit.Assert;
> import org.junit.Test;
> 
> public class ProxyBug {
> 
> 
> @Test
> public void bugWithRequestThroughProxy() throws Exception {
> TrustStrategy trustStrategy = new TrustAllStrategy();
> SSLContext sslContext = new
> SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build();
> SSLConnectionSocketFactory socketFactory = new
> SSLConnectionSocketFactory(sslContext);
> CloseableHttpClient httpclient =
> HttpClients.custom().setSSLSocketFactory(socketFactory).build();
> try {
> 
> HttpHost target = new HttpHost("jmeter.apache.org", 443,
> "https");
> HttpHost proxy = new HttpHost("localhost", , "http");
> 
> RequestConfig config =
> RequestConfig.custom().setProxy(proxy).build();
> HttpGet request = new HttpGet("/");
> request.addHeader("X-sleep", "5");
> request.setConfig(config);
> 
> HttpContext localContext = new BasicHttpContext();
> CloseableHttpResponse response =
> httpclient.execute(target,
> request, localContext);
> final HttpRequest httpRequestFromLocalContext =
> (HttpRequest)
> localContext
> .getAttribute(HttpCoreContext.HTTP_REQUEST);
> try {
> 
> Assert.assertThat(httpRequestFromLocalContext.getRequestLine().getMet
> hod(),
> CoreMatchers.is("GET"));
> Assert.assertThat(response.getStatusLine().getStatusC
> ode(),
> CoreMatchers.is(200));
> 
> Assert.assertThat(Arrays.asList(request.getAllHeaders()).toString(),
> CoreMatchers.containsString("X-sleep"));
> 
> Assert.assertThat(Arrays.asList(httpRequestFromLocalContext.getAllHea
> ders()).toString(),
> CoreMatchers.containsString("X-sleep"));
> 
> } finally {
> response.close();
> }
> } finally {
> httpclient.close();
> }
> }
> 
> @Test
> public void noBugWithDirectRequest() throws Exception {
> TrustStrategy trustStrategy = new TrustAllStrategy();
> SSLContext sslContext = new
> SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build();
> SSLConnectionSocketFactory socketFactory = new
> SSLConnectionSocketFactory(sslContext);
> CloseableHttpClient httpclient =
> HttpClients.custom().setSSLSocketFactory(socketFactory).build();
> try {
> 
> HttpHost target = new HttpHost("jmeter.apache.org", 443,
> "https");
> 
> 

Re: Strange behaviour when using Proxy

2018-12-15 Thread Philippe Mouawad
Hi Oleg,
Is it clear or do you need more details ?

Shall I create a Jira issue ?

Thanks

On Saturday, December 15, 2018, Philippe Mouawad <
p.moua...@ubik-ingenierie.com> wrote:

> Hello,
> I can create a github project but is it worth just for this  ?
> I have reworked the test case to try to be more clear.
>
> Let me reformulate the problem related to this bug report on jmeter:
>
>- https://bz.apache.org/bugzilla/show_bug.cgi?id=62852
>
> The problem is that below method behaves differently if request is emitted
> directly or through a Proxy:
>
>- localContext.getAttribute(HttpCoreContext.HTTP_REQUEST);
>
> If you run code below and inspect:
>
>- localContext.getAttribute(HttpCoreContext.HTTP_REQUEST);
>
> While you  should get this (and you indeed get this if you don't use a
> proxy):
>
>- The GET method
>- All headers:
>   - X-Sleep:5
>   - Host: jmeter.apache.org:443,
>   - User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_161)
>
> Instead you get:
>
>- CONNECT method (the proxy related one)
>- Partial Headers:
>   - Host: jmeter.apache.org:443,
>   - User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_161)
>
> In test case below:
>
>- http://localhost: act as proxy (you can use JMeter HTTP Test
>Script recorder to start a proxy or any proxy implementation running on
>that port)
>- https://jmeter.apache.org is the target website, but you can use any
>site you want
>- X-Sleep is the custom header that is lost for example
>
> 
> ---
>package org.apache.jmeter.protocol.http.proxy;
>
> import java.util.Arrays;
>
> import javax.net.ssl.SSLContext;
>
> import org.apache.http.HttpHost;
> import org.apache.http.HttpRequest;
> import org.apache.http.client.config.RequestConfig;
> import org.apache.http.client.methods.CloseableHttpResponse;
> import org.apache.http.client.methods.HttpGet;
> import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
> import org.apache.http.conn.ssl.TrustAllStrategy;
> import org.apache.http.impl.client.CloseableHttpClient;
> import org.apache.http.impl.client.HttpClients;
> import org.apache.http.protocol.BasicHttpContext;
> import org.apache.http.protocol.HttpContext;
> import org.apache.http.protocol.HttpCoreContext;
> import org.apache.http.ssl.SSLContextBuilder;
> import org.apache.http.ssl.TrustStrategy;
> import org.hamcrest.CoreMatchers;
> import org.junit.Assert;
> import org.junit.Test;
>
> public class ProxyBug {
>
>
> @Test
> public void bugWithRequestThroughProxy() throws Exception {
> TrustStrategy trustStrategy = new TrustAllStrategy();
> SSLContext sslContext = new 
> SSLContextBuilder().loadTrustMaterial(null,
> trustStrategy).build();
> SSLConnectionSocketFactory socketFactory = new
> SSLConnectionSocketFactory(sslContext);
> CloseableHttpClient httpclient = HttpClients.custom().
> setSSLSocketFactory(socketFactory).build();
> try {
>
> HttpHost target = new HttpHost("jmeter.apache.org", 443,
> "https");
> HttpHost proxy = new HttpHost("localhost", , "http");
>
> RequestConfig config = RequestConfig.custom().
> setProxy(proxy).build();
> HttpGet request = new HttpGet("/");
> request.addHeader("X-sleep", "5");
> request.setConfig(config);
>
> HttpContext localContext = new BasicHttpContext();
> CloseableHttpResponse response = httpclient.execute(target,
> request, localContext);
> final HttpRequest httpRequestFromLocalContext = (HttpRequest)
> localContext
> .getAttribute(HttpCoreContext.HTTP_REQUEST);
> try {
> 
> Assert.assertThat(httpRequestFromLocalContext.getRequestLine().getMethod(),
> CoreMatchers.is("GET"));
> Assert.assertThat(response.getStatusLine().getStatusCode(),
> CoreMatchers.is(200));
> Assert.assertThat(Arrays.asList(request.getAllHeaders()
> ).toString(),
> CoreMatchers.containsString("X-sleep"));
> Assert.assertThat(Arrays.asList(
> httpRequestFromLocalContext.getAllHeaders()).toString(),
> CoreMatchers.containsString("X-sleep"));
>
> } finally {
> response.close();
> }
> } finally {
> httpclient.close();
> }
> }
>
> @Test
> public void noBugWithDirectRequest() throws Exception {
> TrustStrategy trustStrategy = new TrustAllStrategy();
> SSLContext sslContext = new 
> SSLContextBuilder().loadTrustMaterial(null,
> trustStrategy).build();
> SSLConnectionSocketFactory socketFactory = new
> SSLConnectionSocketFactory(sslContext);
> CloseableHttpClient httpclient = HttpClients.custom().
> setSSLSocketFactory(socketFactory).build();
> try {
>
> 

Re: Strange behaviour when using Proxy

2018-12-15 Thread Philippe Mouawad
Hello,
I can create a github project but is it worth just for this  ?
I have reworked the test case to try to be more clear.

Let me reformulate the problem related to this bug report on jmeter:

   - https://bz.apache.org/bugzilla/show_bug.cgi?id=62852

The problem is that below method behaves differently if request is emitted
directly or through a Proxy:

   - localContext.getAttribute(HttpCoreContext.HTTP_REQUEST);

If you run code below and inspect:

   - localContext.getAttribute(HttpCoreContext.HTTP_REQUEST);

While you  should get this (and you indeed get this if you don't use a
proxy):

   - The GET method
   - All headers:
  - X-Sleep:5
  - Host: jmeter.apache.org:443,
  - User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_161)

Instead you get:

   - CONNECT method (the proxy related one)
   - Partial Headers:
  - Host: jmeter.apache.org:443,
  - User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_161)

In test case below:

   - http://localhost: act as proxy (you can use JMeter HTTP Test
   Script recorder to start a proxy or any proxy implementation running on
   that port)
   - https://jmeter.apache.org is the target website, but you can use any
   site you want
   - X-Sleep is the custom header that is lost for example

---
   package org.apache.jmeter.protocol.http.proxy;

import java.util.Arrays;

import javax.net.ssl.SSLContext;

import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustAllStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpCoreContext;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Test;

public class ProxyBug {


@Test
public void bugWithRequestThroughProxy() throws Exception {
TrustStrategy trustStrategy = new TrustAllStrategy();
SSLContext sslContext = new
SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build();
SSLConnectionSocketFactory socketFactory = new
SSLConnectionSocketFactory(sslContext);
CloseableHttpClient httpclient =
HttpClients.custom().setSSLSocketFactory(socketFactory).build();
try {

HttpHost target = new HttpHost("jmeter.apache.org", 443,
"https");
HttpHost proxy = new HttpHost("localhost", , "http");

RequestConfig config =
RequestConfig.custom().setProxy(proxy).build();
HttpGet request = new HttpGet("/");
request.addHeader("X-sleep", "5");
request.setConfig(config);

HttpContext localContext = new BasicHttpContext();
CloseableHttpResponse response = httpclient.execute(target,
request, localContext);
final HttpRequest httpRequestFromLocalContext = (HttpRequest)
localContext
.getAttribute(HttpCoreContext.HTTP_REQUEST);
try {

Assert.assertThat(httpRequestFromLocalContext.getRequestLine().getMethod(),
CoreMatchers.is("GET"));
Assert.assertThat(response.getStatusLine().getStatusCode(),
CoreMatchers.is(200));

Assert.assertThat(Arrays.asList(request.getAllHeaders()).toString(),
CoreMatchers.containsString("X-sleep"));

Assert.assertThat(Arrays.asList(httpRequestFromLocalContext.getAllHeaders()).toString(),
CoreMatchers.containsString("X-sleep"));

} finally {
response.close();
}
} finally {
httpclient.close();
}
}

@Test
public void noBugWithDirectRequest() throws Exception {
TrustStrategy trustStrategy = new TrustAllStrategy();
SSLContext sslContext = new
SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build();
SSLConnectionSocketFactory socketFactory = new
SSLConnectionSocketFactory(sslContext);
CloseableHttpClient httpclient =
HttpClients.custom().setSSLSocketFactory(socketFactory).build();
try {

HttpHost target = new HttpHost("jmeter.apache.org", 443,
"https");

RequestConfig config = RequestConfig.custom().build();
HttpGet request = new HttpGet("/");
request.addHeader("X-sleep", "5");
request.setConfig(config);

HttpContext localContext = new BasicHttpContext();
CloseableHttpResponse response = httpclient.execute(target,
request, localContext);
final HttpRequest 

Re: Strange behaviour when using Proxy

2018-12-15 Thread Oleg Kalnichevski
On Sat, 2018-12-15 at 15:09 +0100, Philippe Mouawad wrote:
> Yes, I should have adjusted it.
> The bug for us is that while we should get the GET method in
> localContext.getAttribute(HttpCoreContext.HTTP_REQUEST) we end up
> with the
> proxy related on which is CONNECT and contains only partial headers.
> 

I am sorry I do not understand what it is exactly you consider to be a
problem. Could you please create a GitHub project containing the test
case with the correct asserts that clearly define your expectations?

Oleg 


> Regards
> 
> On Sat, Dec 15, 2018 at 2:57 PM Oleg Kalnichevski 
> wrote:
> 
> > On Sat, 2018-12-15 at 14:51 +0100, Philippe Mouawad wrote:
> > > Hello Oleg,
> > > Felix has created a JUnit test that shows our issue:
> > > 
> > >- We use localhost: as proxy
> > >- And https://jmeter.apache.org is the target site
> > > 
> > > Note that in JMeter we use the HttpRequest from HttpContext as it
> > > contains
> > > all the headers :
> > > 
> > >- [Host: jmeter.apache.org:443, User-Agent: Apache-
> > > HttpClient/4.5.6
> > >(Java/1.8.0_161)]
> > >- It should also contains X-sleep: 5 but as you will see, it
> > > doesn't
> > > 
> > > 
> > > 
> > > @Test
> > > public void checkThatHeadersAreNotHidden() throws Exception {
> > > TrustStrategy trustStrategy = new TrustAllStrategy();
> > > SSLContext sslContext = new
> > > SSLContextBuilder().loadTrustMaterial(null,
> > > trustStrategy).build();
> > > SSLConnectionSocketFactory socketFactory = new
> > > SSLConnectionSocketFactory(sslContext);
> > > CloseableHttpClient httpclient =
> > > HttpClients.custom().setSSLSocketFactory(socketFactory).build();
> > > try {
> > > 
> > > HttpHost target = new HttpHost("jmeter.apache.org",
> > > 443,
> > > "https");
> > > HttpHost proxy = new HttpHost("localhost", ,
> > > "http");
> > > 
> > > RequestConfig config =
> > > RequestConfig.custom().setProxy(proxy).build();
> > > HttpGet request = new HttpGet("/");
> > > request.addHeader("X-sleep", "5");
> > > request.setConfig(config);
> > > 
> > > HttpContext localContext = new BasicHttpContext();
> > > CloseableHttpResponse response =
> > > httpclient.execute(target,
> > > request, localContext);
> > > final HttpRequest httpRequestFromLocalContext =
> > > (HttpRequest)
> > > localContext
> > > .getAttribute(HttpCoreContext.HTTP_REQUEST);
> > > try {
> > > 
> > > Assert.assertThat(httpRequestFromLocalContext.getRequestLine().ge
> > > tMet
> > > hod(),
> > > CoreMatchers.is("CONNECT"));
> > 
> > This assert does not make sense to me. Why would one expect the
> > method
> > to be CONNECT when clearly GET is being issued?
> > 
> > Oleg
> > 
> > 
> > > Assert.assertThat(response.getStatusLine().getSta
> > > tusC
> > > ode(),
> > > CoreMatchers.is(200));
> > > 
> > > Assert.assertThat(Arrays.asList(request.getAllHeaders()).toString
> > > (),
> > > CoreMatchers.containsString("X-sleep"));
> > > 
> > > Assert.assertThat(Arrays.asList(httpRequestFromLocalContext.getAl
> > > lHea
> > > ders()).toString(),
> > > CoreMatchers.containsString("X-sleep"));
> > > } finally {
> > > response.close();
> > > }
> > > } finally {
> > > httpclient.close();
> > > }
> > > }
> > > 
> > > On Sat, Dec 15, 2018 at 2:35 PM Oleg Kalnichevski <
> > > ol...@apache.org>
> > > wrote:
> > > 
> > > > On Sat, 2018-12-15 at 00:40 +0100, Philippe Mouawad wrote:
> > > > > Hello ,
> > > > > As a complement if you read the thread.
> > > > > It appears TestProxy doesn’t enter in Tunnel_target mode
> > > > > while
> > > > > JMeter
> > > > > does
> > > > > which triggers the issue.
> > > > > 
> > > > > How can I make HttpClient enter this mode using TestProxy
> > > > > code
> > > > > (in
> > > > > thread)
> > > > > below so that I can provide a reproducer for issue?
> > > > 
> > > > You need to make sure the route is marked as
> > > > TunnelType.TUNNELLED.
> > > > Secure `https` routes are marked TunnelType.TUNNELLED by
> > > > default.
> > > > 
> > > > Oleg
> > > > 
> > > > 
> > > > > I tried debugging but I don’t understand, it seems it depends
> > > > > on
> > > > > number of
> > > > > Hop in httpRoute, but javadocs is very succinct.
> > > > > 
> > > > > Thanks
> > > > > 
> > > > > On Friday, December 14, 2018, Philippe Mouawad <
> > > > > pmoua...@apache.org>
> > > > > wrote:
> > > > > 
> > > > > > Hello,
> > > > > > We have a bug report at JMeter where request headers are
> > > > > > lost
> > > > > > when
> > > > > > a proxy
> > > > > > is used for a request.
> > > > > > 
> > > > > > You can see thread discussion here:
> > > > > > 
> > > > > > http://mail-archives.apache.org/mod_mbox/jmeter-dev/
> > > > > > 
> > > > 
> > > > 
> > 
> > 

Re: Strange behaviour when using Proxy

2018-12-15 Thread Philippe Mouawad
Yes, I should have adjusted it.
The bug for us is that while we should get the GET method in
localContext.getAttribute(HttpCoreContext.HTTP_REQUEST) we end up with the
proxy related on which is CONNECT and contains only partial headers.

Regards

On Sat, Dec 15, 2018 at 2:57 PM Oleg Kalnichevski  wrote:

> On Sat, 2018-12-15 at 14:51 +0100, Philippe Mouawad wrote:
> > Hello Oleg,
> > Felix has created a JUnit test that shows our issue:
> >
> >- We use localhost: as proxy
> >- And https://jmeter.apache.org is the target site
> >
> > Note that in JMeter we use the HttpRequest from HttpContext as it
> > contains
> > all the headers :
> >
> >- [Host: jmeter.apache.org:443, User-Agent: Apache-
> > HttpClient/4.5.6
> >(Java/1.8.0_161)]
> >- It should also contains X-sleep: 5 but as you will see, it
> > doesn't
> >
> >
> >
> > @Test
> > public void checkThatHeadersAreNotHidden() throws Exception {
> > TrustStrategy trustStrategy = new TrustAllStrategy();
> > SSLContext sslContext = new
> > SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build();
> > SSLConnectionSocketFactory socketFactory = new
> > SSLConnectionSocketFactory(sslContext);
> > CloseableHttpClient httpclient =
> > HttpClients.custom().setSSLSocketFactory(socketFactory).build();
> > try {
> >
> > HttpHost target = new HttpHost("jmeter.apache.org", 443,
> > "https");
> > HttpHost proxy = new HttpHost("localhost", , "http");
> >
> > RequestConfig config =
> > RequestConfig.custom().setProxy(proxy).build();
> > HttpGet request = new HttpGet("/");
> > request.addHeader("X-sleep", "5");
> > request.setConfig(config);
> >
> > HttpContext localContext = new BasicHttpContext();
> > CloseableHttpResponse response =
> > httpclient.execute(target,
> > request, localContext);
> > final HttpRequest httpRequestFromLocalContext =
> > (HttpRequest)
> > localContext
> > .getAttribute(HttpCoreContext.HTTP_REQUEST);
> > try {
> >
> > Assert.assertThat(httpRequestFromLocalContext.getRequestLine().getMet
> > hod(),
> > CoreMatchers.is("CONNECT"));
>
> This assert does not make sense to me. Why would one expect the method
> to be CONNECT when clearly GET is being issued?
>
> Oleg
>
>
> > Assert.assertThat(response.getStatusLine().getStatusC
> > ode(),
> > CoreMatchers.is(200));
> >
> > Assert.assertThat(Arrays.asList(request.getAllHeaders()).toString(),
> > CoreMatchers.containsString("X-sleep"));
> >
> > Assert.assertThat(Arrays.asList(httpRequestFromLocalContext.getAllHea
> > ders()).toString(),
> > CoreMatchers.containsString("X-sleep"));
> > } finally {
> > response.close();
> > }
> > } finally {
> > httpclient.close();
> > }
> > }
> >
> > On Sat, Dec 15, 2018 at 2:35 PM Oleg Kalnichevski 
> > wrote:
> >
> > > On Sat, 2018-12-15 at 00:40 +0100, Philippe Mouawad wrote:
> > > > Hello ,
> > > > As a complement if you read the thread.
> > > > It appears TestProxy doesn’t enter in Tunnel_target mode while
> > > > JMeter
> > > > does
> > > > which triggers the issue.
> > > >
> > > > How can I make HttpClient enter this mode using TestProxy code
> > > > (in
> > > > thread)
> > > > below so that I can provide a reproducer for issue?
> > >
> > > You need to make sure the route is marked as TunnelType.TUNNELLED.
> > > Secure `https` routes are marked TunnelType.TUNNELLED by default.
> > >
> > > Oleg
> > >
> > >
> > > > I tried debugging but I don’t understand, it seems it depends on
> > > > number of
> > > > Hop in httpRoute, but javadocs is very succinct.
> > > >
> > > > Thanks
> > > >
> > > > On Friday, December 14, 2018, Philippe Mouawad <
> > > > pmoua...@apache.org>
> > > > wrote:
> > > >
> > > > > Hello,
> > > > > We have a bug report at JMeter where request headers are lost
> > > > > when
> > > > > a proxy
> > > > > is used for a request.
> > > > >
> > > > > You can see thread discussion here:
> > > > >
> > > > > http://mail-archives.apache.org/mod_mbox/jmeter-dev/
> > > > >
> > >
> > >
> 201812.mbox/%3cf1831746-eeb7-c0df-75e2-565cc2c56...@internetallee.de
> > > > > %3e
> > > > >
> > > > >
> > > > > It seems hc4 swaps the request stored in local context leading
> > > > > to
> > > > > the
> > > > > issue.
> > > > >
> > > > >
> > > > > Regards
> > > > >
> > >
> > >
> > > -
> > > 
> > > To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
> > > For additional commands, e-mail:
> > > httpclient-users-h...@hc.apache.org
> > >
> > >
> >
> >
>
>
> -
> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
> For additional commands, e-mail: 

Re: Strange behaviour when using Proxy

2018-12-15 Thread Oleg Kalnichevski
On Sat, 2018-12-15 at 14:51 +0100, Philippe Mouawad wrote:
> Hello Oleg,
> Felix has created a JUnit test that shows our issue:
> 
>- We use localhost: as proxy
>- And https://jmeter.apache.org is the target site
> 
> Note that in JMeter we use the HttpRequest from HttpContext as it
> contains
> all the headers :
> 
>- [Host: jmeter.apache.org:443, User-Agent: Apache-
> HttpClient/4.5.6
>(Java/1.8.0_161)]
>- It should also contains X-sleep: 5 but as you will see, it
> doesn't
> 
> 
> 
> @Test
> public void checkThatHeadersAreNotHidden() throws Exception {
> TrustStrategy trustStrategy = new TrustAllStrategy();
> SSLContext sslContext = new
> SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build();
> SSLConnectionSocketFactory socketFactory = new
> SSLConnectionSocketFactory(sslContext);
> CloseableHttpClient httpclient =
> HttpClients.custom().setSSLSocketFactory(socketFactory).build();
> try {
> 
> HttpHost target = new HttpHost("jmeter.apache.org", 443,
> "https");
> HttpHost proxy = new HttpHost("localhost", , "http");
> 
> RequestConfig config =
> RequestConfig.custom().setProxy(proxy).build();
> HttpGet request = new HttpGet("/");
> request.addHeader("X-sleep", "5");
> request.setConfig(config);
> 
> HttpContext localContext = new BasicHttpContext();
> CloseableHttpResponse response =
> httpclient.execute(target,
> request, localContext);
> final HttpRequest httpRequestFromLocalContext =
> (HttpRequest)
> localContext
> .getAttribute(HttpCoreContext.HTTP_REQUEST);
> try {
> 
> Assert.assertThat(httpRequestFromLocalContext.getRequestLine().getMet
> hod(),
> CoreMatchers.is("CONNECT"));

This assert does not make sense to me. Why would one expect the method
to be CONNECT when clearly GET is being issued?

Oleg 


> Assert.assertThat(response.getStatusLine().getStatusC
> ode(),
> CoreMatchers.is(200));
> 
> Assert.assertThat(Arrays.asList(request.getAllHeaders()).toString(),
> CoreMatchers.containsString("X-sleep"));
> 
> Assert.assertThat(Arrays.asList(httpRequestFromLocalContext.getAllHea
> ders()).toString(),
> CoreMatchers.containsString("X-sleep"));
> } finally {
> response.close();
> }
> } finally {
> httpclient.close();
> }
> }
> 
> On Sat, Dec 15, 2018 at 2:35 PM Oleg Kalnichevski 
> wrote:
> 
> > On Sat, 2018-12-15 at 00:40 +0100, Philippe Mouawad wrote:
> > > Hello ,
> > > As a complement if you read the thread.
> > > It appears TestProxy doesn’t enter in Tunnel_target mode while
> > > JMeter
> > > does
> > > which triggers the issue.
> > > 
> > > How can I make HttpClient enter this mode using TestProxy code
> > > (in
> > > thread)
> > > below so that I can provide a reproducer for issue?
> > 
> > You need to make sure the route is marked as TunnelType.TUNNELLED.
> > Secure `https` routes are marked TunnelType.TUNNELLED by default.
> > 
> > Oleg
> > 
> > 
> > > I tried debugging but I don’t understand, it seems it depends on
> > > number of
> > > Hop in httpRoute, but javadocs is very succinct.
> > > 
> > > Thanks
> > > 
> > > On Friday, December 14, 2018, Philippe Mouawad <
> > > pmoua...@apache.org>
> > > wrote:
> > > 
> > > > Hello,
> > > > We have a bug report at JMeter where request headers are lost
> > > > when
> > > > a proxy
> > > > is used for a request.
> > > > 
> > > > You can see thread discussion here:
> > > > 
> > > > http://mail-archives.apache.org/mod_mbox/jmeter-dev/
> > > > 
> > 
> > 
201812.mbox/%3cf1831746-eeb7-c0df-75e2-565cc2c56...@internetallee.de
> > > > %3e
> > > > 
> > > > 
> > > > It seems hc4 swaps the request stored in local context leading
> > > > to
> > > > the
> > > > issue.
> > > > 
> > > > 
> > > > Regards
> > > > 
> > 
> > 
> > -
> > 
> > To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
> > For additional commands, e-mail: 
> > httpclient-users-h...@hc.apache.org
> > 
> > 
> 
> 


-
To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
For additional commands, e-mail: httpclient-users-h...@hc.apache.org



Re: Strange behaviour when using Proxy

2018-12-15 Thread Philippe Mouawad
Hello Oleg,
Felix has created a JUnit test that shows our issue:

   - We use localhost: as proxy
   - And https://jmeter.apache.org is the target site

Note that in JMeter we use the HttpRequest from HttpContext as it contains
all the headers :

   - [Host: jmeter.apache.org:443, User-Agent: Apache-HttpClient/4.5.6
   (Java/1.8.0_161)]
   - It should also contains X-sleep: 5 but as you will see, it doesn't



@Test
public void checkThatHeadersAreNotHidden() throws Exception {
TrustStrategy trustStrategy = new TrustAllStrategy();
SSLContext sslContext = new
SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build();
SSLConnectionSocketFactory socketFactory = new
SSLConnectionSocketFactory(sslContext);
CloseableHttpClient httpclient =
HttpClients.custom().setSSLSocketFactory(socketFactory).build();
try {

HttpHost target = new HttpHost("jmeter.apache.org", 443,
"https");
HttpHost proxy = new HttpHost("localhost", , "http");

RequestConfig config =
RequestConfig.custom().setProxy(proxy).build();
HttpGet request = new HttpGet("/");
request.addHeader("X-sleep", "5");
request.setConfig(config);

HttpContext localContext = new BasicHttpContext();
CloseableHttpResponse response = httpclient.execute(target,
request, localContext);
final HttpRequest httpRequestFromLocalContext = (HttpRequest)
localContext
.getAttribute(HttpCoreContext.HTTP_REQUEST);
try {

Assert.assertThat(httpRequestFromLocalContext.getRequestLine().getMethod(),
CoreMatchers.is("CONNECT"));
Assert.assertThat(response.getStatusLine().getStatusCode(),
CoreMatchers.is(200));

Assert.assertThat(Arrays.asList(request.getAllHeaders()).toString(),
CoreMatchers.containsString("X-sleep"));

Assert.assertThat(Arrays.asList(httpRequestFromLocalContext.getAllHeaders()).toString(),
CoreMatchers.containsString("X-sleep"));
} finally {
response.close();
}
} finally {
httpclient.close();
}
}

On Sat, Dec 15, 2018 at 2:35 PM Oleg Kalnichevski  wrote:

> On Sat, 2018-12-15 at 00:40 +0100, Philippe Mouawad wrote:
> > Hello ,
> > As a complement if you read the thread.
> > It appears TestProxy doesn’t enter in Tunnel_target mode while JMeter
> > does
> > which triggers the issue.
> >
> > How can I make HttpClient enter this mode using TestProxy code (in
> > thread)
> > below so that I can provide a reproducer for issue?
>
> You need to make sure the route is marked as TunnelType.TUNNELLED.
> Secure `https` routes are marked TunnelType.TUNNELLED by default.
>
> Oleg
>
>
> > I tried debugging but I don’t understand, it seems it depends on
> > number of
> > Hop in httpRoute, but javadocs is very succinct.
> >
> > Thanks
> >
> > On Friday, December 14, 2018, Philippe Mouawad 
> > wrote:
> >
> > > Hello,
> > > We have a bug report at JMeter where request headers are lost when
> > > a proxy
> > > is used for a request.
> > >
> > > You can see thread discussion here:
> > >
> > > http://mail-archives.apache.org/mod_mbox/jmeter-dev/
> > >
> 201812.mbox/%3cf1831746-eeb7-c0df-75e2-565cc2c56...@internetallee.de
> > > %3e
> > >
> > >
> > > It seems hc4 swaps the request stored in local context leading to
> > > the
> > > issue.
> > >
> > >
> > > Regards
> > >
>
>
> -
> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
> For additional commands, e-mail: httpclient-users-h...@hc.apache.org
>
>

-- 


[image: logo Ubik Ingenierie]  Philippe
Mouawad
320914981 <+33320914981> | p.moua...@ubik-ingenierie.com
[image: ubik-ingenierie.com] ubik-ingenierie.com
 | [image: 03.20.91.49.81] 03.20.91.49.81
<+33320914981> | [image: 23 rue du chemin de fer , 59100 , Roubaix] 23 rue
du chemin de fer, 59100, Roubaix



Re: Strange behaviour when using Proxy

2018-12-15 Thread Oleg Kalnichevski
On Sat, 2018-12-15 at 00:40 +0100, Philippe Mouawad wrote:
> Hello ,
> As a complement if you read the thread.
> It appears TestProxy doesn’t enter in Tunnel_target mode while JMeter
> does
> which triggers the issue.
> 
> How can I make HttpClient enter this mode using TestProxy code (in
> thread)
> below so that I can provide a reproducer for issue?

You need to make sure the route is marked as TunnelType.TUNNELLED.
Secure `https` routes are marked TunnelType.TUNNELLED by default.

Oleg


> I tried debugging but I don’t understand, it seems it depends on
> number of
> Hop in httpRoute, but javadocs is very succinct.
> 
> Thanks
> 
> On Friday, December 14, 2018, Philippe Mouawad 
> wrote:
> 
> > Hello,
> > We have a bug report at JMeter where request headers are lost when
> > a proxy
> > is used for a request.
> > 
> > You can see thread discussion here:
> > 
> > http://mail-archives.apache.org/mod_mbox/jmeter-dev/
> > 
201812.mbox/%3cf1831746-eeb7-c0df-75e2-565cc2c56...@internetallee.de
> > %3e
> > 
> > 
> > It seems hc4 swaps the request stored in local context leading to
> > the
> > issue.
> > 
> > 
> > Regards
> > 


-
To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
For additional commands, e-mail: httpclient-users-h...@hc.apache.org



Re: Strange behaviour when using Proxy

2018-12-14 Thread Philippe Mouawad
Hello ,
As a complement if you read the thread.
It appears TestProxy doesn’t enter in Tunnel_target mode while JMeter does
which triggers the issue.

How can I make HttpClient enter this mode using TestProxy code (in thread)
below so that I can provide a reproducer for issue?
I tried debugging but I don’t understand, it seems it depends on number of
Hop in httpRoute, but javadocs is very succinct.

Thanks

On Friday, December 14, 2018, Philippe Mouawad  wrote:

> Hello,
> We have a bug report at JMeter where request headers are lost when a proxy
> is used for a request.
>
> You can see thread discussion here:
>
> http://mail-archives.apache.org/mod_mbox/jmeter-dev/
> 201812.mbox/%3cf1831746-eeb7-c0df-75e2-565cc2c56...@internetallee.de%3e
>
>
> It seems hc4 swaps the request stored in local context leading to the
> issue.
>
>
> Regards
>