HTTPResponse.getHeaders() returns a key-value map. The problem is when there are multiple headers with the same name (e.g. there is often multiple ‘set-cookie’ headers), as you only get access to the one defined last.
How do I access all the headers of the same name?
Try
getAllHeaders()which returns an array of values for each key instead (precisely for this reason).