Hello, Thanks . Done: https://issues.apache.org/jira/browse/HTTPCLIENT-1956
Regards On Sat, Dec 15, 2018 at 9:54 PM Oleg Kalnichevski <[email protected]> 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:8888 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", 8888, "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"); > > > > 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 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(); > > } > > } > > } > > > > ------------------------------------------------------------------- > > -------------------------------- > > > > On Sat, Dec 15, 2018 at 3:11 PM Oleg Kalnichevski <[email protected]> > > wrote: > > > > > 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 < > > > > [email protected]> > > > > 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:8888 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", 8888, > > > > > > "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_REQUES > > > > > > T); > > > > > > 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().ge > > > > > > tSta > > > > > > tusC > > > > > > ode(), > > > > > > CoreMatchers.is(200)); > > > > > > > > > > > > Assert.assertThat(Arrays.asList(request.getAllHeaders()).toSt > > > > > > ring > > > > > > (), > > > > > > CoreMatchers.containsString("X- > > > > > > sleep")); > > > > > > > > > > > > Assert.assertThat(Arrays.asList(httpRequestFromLocalContext.g > > > > > > etAl > > > > > > lHea > > > > > > ders()).toString(), > > > > > > CoreMatchers.containsString("X- > > > > > > sleep")); > > > > > > } finally { > > > > > > response.close(); > > > > > > } > > > > > > } finally { > > > > > > httpclient.close(); > > > > > > } > > > > > > } > > > > > > > > > > > > On Sat, Dec 15, 2018 at 2:35 PM Oleg Kalnichevski < > > > > > > [email protected]> > > > > > > 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 < > > > > > > > > [email protected]> > > > > > > > > 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/%[email protected] > > > > > > > > > %3e > > > > > > > > > > > > > > > > > > > > > > > > > > > It seems hc4 swaps the request stored in local context > > > > > > > > > leading > > > > > > > > > to > > > > > > > > > the > > > > > > > > > issue. > > > > > > > > > > > > > > > > > > > > > > > > > > > Regards > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --------------------------------------------------------- > > > > > > > ---- > > > > > > > ---- > > > > > > > ---- > > > > > > > To unsubscribe, e-mail: > > > > > > > [email protected] > > > > > > > For additional commands, e-mail: > > > > > > > [email protected] > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------------------------------- > > > > > ---- > > > > > ---- > > > > > To unsubscribe, e-mail: > > > > > [email protected] > > > > > For additional commands, e-mail: > > > > > [email protected] > > > > > > > > > > > > > > > > > > > > > > > > > > > ----------------------------------------------------------------- > > > ---- > > > To unsubscribe, e-mail: [email protected] > > > For additional commands, e-mail: > > > [email protected] > > > > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > -- [image: logo Ubik Ingenierie] <https://www.ubik-ingenierie.com> Philippe Mouawad 320914981 <+33320914981> | [email protected] [image: ubik-ingenierie.com] ubik-ingenierie.com <https://www.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 <https://www.openstreetmap.org/#map=18/50.69454/3.16455>
