hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Kalnichevski (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (HTTPCLIENT-1794) Cookies not forwarded through proxies
Date Wed, 07 Dec 2016 13:39:59 GMT

     [ https://issues.apache.org/jira/browse/HTTPCLIENT-1794?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Oleg Kalnichevski resolved HTTPCLIENT-1794.
-------------------------------------------
    Resolution: Invalid

Jens,
This problem has nothing to do with forwarding the request via a proxy. 
The effective domain of the cookie does not match that of the cookie origin and the cookie
does not get included in the request regardless of the proxy settings.

Either set the effective to match that of the cookie origin
{code:java}
BasicClientCookie cookie = new BasicClientCookie("oraclelicense", "accept-securebackup-cookie");
cookie.setDomain("download.oracle.com");
{code}
or add explicit domain attribute to the cookie
{code:java}
BasicClientCookie cookie = new BasicClientCookie("oraclelicense", "accept-securebackup-cookie");
cookie.setDomain(".oracle.com");
cookie.setAttribute(Cookie.DOMAIN_ATTR, ".oracle.com");
{code}

Oleg


> Cookies not forwarded through proxies
> -------------------------------------
>
>                 Key: HTTPCLIENT-1794
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1794
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient (classic)
>    Affects Versions: 4.5.2
>         Environment: win32_64
>            Reporter: Jens K├╝bler
>
> Cookies are not being sent through proxies.
> See  the following code. This does only work when the commented line is being set.
> package vi.java;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.io.InputStream;
> import org.apache.http.HttpEntity;
> import org.apache.http.HttpHost;
> import org.apache.http.HttpResponse;
> import org.apache.http.auth.AuthScope;
> import org.apache.http.auth.UsernamePasswordCredentials;
> import org.apache.http.client.ClientProtocolException;
> import org.apache.http.client.CookieStore;
> import org.apache.http.client.CredentialsProvider;
> import org.apache.http.client.HttpClient;
> import org.apache.http.client.config.CookieSpecs;
> import org.apache.http.client.config.RequestConfig;
> import org.apache.http.client.methods.HttpGet;
> import org.apache.http.impl.client.BasicCookieStore;
> import org.apache.http.impl.client.BasicCredentialsProvider;
> import org.apache.http.impl.client.HttpClientBuilder;
> import org.apache.http.impl.cookie.BasicClientCookie;
> public class ProxyCookieExample {
> 	public static void main(String args[]) throws ClientProtocolException, IOException {
> 		CookieStore cookieStore = new BasicCookieStore();
> 		// Populate cookies if needed
> 		BasicClientCookie cookie = new BasicClientCookie("oraclelicense", "accept-securebackup-cookie");
> 		cookie.setDomain(".oracle.com");
> 		cookie.setPath("/");
> 		cookieStore.addCookie(cookie);
> 		
> 		CredentialsProvider credsProvider = new BasicCredentialsProvider();
> 		credsProvider.setCredentials(
> 				new AuthScope("myproxy", 8080),
> 				new UsernamePasswordCredentials("user", "password"));
> 		
> 		HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).setDefaultCredentialsProvider(credsProvider).build();
> 		HttpHost proxy = new HttpHost("myproxy", 8080);
> 		
> 		RequestConfig config = RequestConfig.custom()
>                 .setProxy(proxy)
>                 .setCookieSpec(CookieSpecs.DEFAULT)
>                 .build();
> 		
> 		HttpGet httpGet = new HttpGet("http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-windows-i586.exe");
> //		httpGet.addHeader("Cookie","oraclelicense=accept-securebackup-cookie");
> 		httpGet.setConfig(config);
> 		
> 		HttpResponse response1 = client.execute(httpGet);
> 		
> 	    HttpEntity entity1 = response1.getEntity();
> 	    InputStream content = entity1.getContent();
> 	    try(FileOutputStream fileOutputStream = new FileOutputStream("jdk-8u112-windows-i586.exe"))
{
> 	    	byte[] buffer = new byte[16384]; // Adjust if you want
> 	    	int bytesRead;
> 	    	while ((bytesRead = content.read(buffer)) != -1)
> 	    	{
> 	    		fileOutputStream.write(buffer, 0, bytesRead);
> 	    	}		    
> 	    }
> 	}
> 	
> }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message