mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:57:44 +00:00
LibWeb+LibHTTP: Support multiple Set-Cookie response headers
This commit is contained in:
parent
0e873464ed
commit
57541f433b
3 changed files with 29 additions and 5 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/JsonArray.h>
|
||||
#include <LibCompress/Gzip.h>
|
||||
#include <LibCompress/Zlib.h>
|
||||
#include <LibCore/Event.h>
|
||||
|
@ -179,8 +180,11 @@ void Job::on_socket_connected()
|
|||
if (m_state == State::Trailers) {
|
||||
return finish_up();
|
||||
} else {
|
||||
if (on_headers_received)
|
||||
if (on_headers_received) {
|
||||
if (!m_set_cookie_headers.is_empty())
|
||||
m_headers.set("Set-Cookie", JsonArray { m_set_cookie_headers }.to_string());
|
||||
on_headers_received(m_headers, m_code > 0 ? m_code : Optional<u32> {});
|
||||
}
|
||||
m_state = State::InBody;
|
||||
}
|
||||
|
||||
|
@ -216,7 +220,20 @@ void Job::on_socket_connected()
|
|||
return deferred_invoke([this] { did_fail(Core::NetworkJob::Error::ProtocolFailed); });
|
||||
}
|
||||
auto value = line.substring(name.length() + 2, line.length() - name.length() - 2);
|
||||
m_headers.set(name, value);
|
||||
if (name.equals_ignoring_case("Set-Cookie")) {
|
||||
dbgln_if(JOB_DEBUG, "Job: Received Set-Cookie header: '{}'", value);
|
||||
m_set_cookie_headers.append(move(value));
|
||||
return;
|
||||
}
|
||||
if (auto existing_value = m_headers.get(name); existing_value.has_value()) {
|
||||
StringBuilder builder;
|
||||
builder.append(existing_value.value());
|
||||
builder.append(',');
|
||||
builder.append(value);
|
||||
m_headers.set(name, builder.build());
|
||||
} else {
|
||||
m_headers.set(name, value);
|
||||
}
|
||||
if (name.equals_ignoring_case("Content-Encoding")) {
|
||||
// Assume that any content-encoding means that we can't decode it as a stream :(
|
||||
dbgln_if(JOB_DEBUG, "Content-Encoding {} detected, cannot stream output :(", value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue