From 38309d0dd12eb3e07f0fa1293f95e1dd771e67ba Mon Sep 17 00:00:00 2001 From: luowei Date: Thu, 29 Feb 2024 17:38:21 +0800 Subject: [PATCH] fix:Session cookie not set --- .../burgstaller/okhttp/digest/DigestAuthenticator.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/burgstaller/okhttp/digest/DigestAuthenticator.java b/src/main/java/com/burgstaller/okhttp/digest/DigestAuthenticator.java index 90b5bb9..b10d164 100644 --- a/src/main/java/com/burgstaller/okhttp/digest/DigestAuthenticator.java +++ b/src/main/java/com/burgstaller/okhttp/digest/DigestAuthenticator.java @@ -188,7 +188,13 @@ public synchronized Request authenticate(Route route, Response response) throws throw new IOException("missing nonce in challenge header: " + header); } - return authenticateWithState(route, response.request(), parameters); + Request request = authenticateWithState(route, response.request(), parameters); + List cookies = response.headers().values("Set-Cookie"); + if (request != null && !cookies.isEmpty()) { + String cookie = cookies.get(0).split(";")[0]; + return request.newBuilder().header("Cookie", cookie).build(); + } + return request; } private String getHeaderName(int httpStatus) {