1.1.1
OkHttp client
1.8.0_181-b13
I鈥檓 running in to some unexpected behavior with ktor-client where I make a request that receives a couple of 302 redirections, some of which set cookies. However the cookies are not being set which leads to the final request failing because it needs the cookies set by the earlier requests. When setting breakpoints it only appears as though the HttpCookies client-feature is only updating cookies when the final response is received rather than also on the redirections. Is this intended behavior?
Hi @alexanderdrm, thanks for the report.
What redirect feature do you use(ktor or okhttp)? It could be okhttp interoperability issue.
A quick look seems to indicate that it's working with the Apache engine, so it seems like it might be an okhttp engine issue.
I am able to reproduce this bug too. Client is okhttp
Assume we have a service that responds with "302 Found" status, gives you cookies and redirects you to another page.
Actual result: request to redirected url is executed without cookies
Expected result: request to redirected url is executed with cookies set.
Tested on CIO client, it works fine
Fixed in 1.2.2
Hello @e5l . I can't confirm bug https://github.com/ktorio/ktor/issues/843 is fixed in 1.2.2
I have a script in php with following content:
<?
if (array_key_exists('TestCookie1', $_COOKIE)) {
print("<pre><b>COOKIES ARE SET !</b><br/>".print_r($_COOKIE,true)."</pre>");
}
else
{
setcookie("TestCookie1", 100000 + rand(100, 500) + ".");
setcookie("TestCookie2", 200000 + rand(100, 500) + ".");
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
header('Location: '.$actual_link, true, 302);
exit;
}
?>
And okhttp client gives me an error:
sources.kts:34 java.net.ProtocolException: Too many follow-up requests: 21
The configuration of OkHttp client:
val client = HttpClient(OkHttp) {
engine {
config {
followRedirects(true)
followSslRedirects(true)
}
}
install(HttpCookies) {
storage = AcceptAllCookiesStorage()
}
}
Android client and CIO work fine.
The configuration of CIO client:
val client = HttpClient(CIO).config {
install(HttpCookies) {
storage = AcceptAllCookiesStorage()
}
}
Android client:
val client = HttpClient(Android) {
install(HttpCookies) {
storage = AcceptAllCookiesStorage()
}
}
Used ktor version: 1.2.2
Most helpful comment
A quick look seems to indicate that it's working with the Apache engine, so it seems like it might be an
okhttpengine issue.