Reputation: 136
We try to use jsoup for retrieving a page from a dedicated server, mix certain HTML in and then return that html in a HTTPServletResponse. Works fine for our requirement. We need to pass the headers from the server that we request back to the client that requests our servlet. This also works fine basically by copying over the received headers to the response. However, if the requested server issues a Set-Cookie
header, this one is stripped from the response and so cannot be returned back from the servlet.
At the moment I have no idea of how we can access the Set-Cookie
header from within the jsoup result.
Any idea (besides switching the framework) is welcome.
Upvotes: 0
Views: 1449
Reputation: 13663
Jsoup stores received cookies in the Connection.Response
object, accessible with the cookie
method. But note (from the docs):
Response objects have a simplified cookie model. Each cookie set in the response is added to the response object's cookie key=value map. The cookie's path, domain, and expiry date are ignored.
So Jsoup ignores some of the information necessary to forward the Set-Cookie
header. Your forwarding server can generate this information on its own (if it knows, e.g., the cookie always expires in an hour), or you can fetch the page manually (without Jsoup), then use Jsoup to parse the response body only, handling the headers yourself.
Upvotes: 2