Allow response header value to contain a colon
HTTP response header field values are allowed to contain separators (which includes the colon) as long as they appear within quotes (http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2). This commit enables `Browser#response_headers` to handle a field value that contains a colon followed by a space (i.e., ": ") without breaking.
This commit is contained in:
parent
e8cc0fa382
commit
c0c9d701ef
|
@ -71,7 +71,7 @@ module Capybara::Webkit
|
|||
end
|
||||
|
||||
def response_headers
|
||||
Hash[command("Headers").split("\n").map { |header| header.split(": ") }]
|
||||
JSON.parse(command("Headers"))
|
||||
end
|
||||
|
||||
def current_url
|
||||
|
|
|
@ -2974,6 +2974,24 @@ CACHE MANIFEST
|
|||
end
|
||||
end
|
||||
|
||||
context "response header contains colon" do
|
||||
let(:driver) do
|
||||
driver_for_app do
|
||||
get "/" do
|
||||
headers "Content-Disposition" => 'filename="File: name.txt"'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "sets the response header" do
|
||||
visit("/")
|
||||
|
||||
expect(
|
||||
driver.response_headers["Content-Disposition"]
|
||||
).to eq 'filename="File: name.txt"'
|
||||
end
|
||||
end
|
||||
|
||||
def driver_url(driver, path)
|
||||
URI.parse(driver.current_url).merge(path).to_s
|
||||
end
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
#include "Headers.h"
|
||||
#include "WebPage.h"
|
||||
#include "WebPageManager.h"
|
||||
#include "JsonSerializer.h"
|
||||
|
||||
Headers::Headers(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
|
||||
}
|
||||
|
||||
void Headers::start() {
|
||||
finish(true, page()->pageHeaders().join("\n"));
|
||||
JsonSerializer serializer;
|
||||
QByteArray json = serializer.serialize(page()->pageHeaders());
|
||||
finish(true, json);
|
||||
}
|
||||
|
||||
|
|
|
@ -83,9 +83,9 @@ void WebPage::setFrameProperties(QWebFrame *frame, QUrl &requestedUrl, NetworkRe
|
|||
if (frame->requestedUrl() == requestedUrl) {
|
||||
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
frame->setProperty("statusCode", statusCode);
|
||||
QStringList headers;
|
||||
QVariantMap headers;
|
||||
foreach(QNetworkReply::RawHeaderPair header, reply->rawHeaderPairs())
|
||||
headers << header.first+": "+header.second;
|
||||
headers[header.first] = QString(header.second);
|
||||
frame->setProperty("headers", headers);
|
||||
frame->setProperty("body", reply->data());
|
||||
QVariant contentMimeType = reply->header(QNetworkRequest::ContentTypeHeader);
|
||||
|
@ -359,8 +359,8 @@ int WebPage::getLastStatus() {
|
|||
return currentFrame()->property("statusCode").toInt();
|
||||
}
|
||||
|
||||
QStringList WebPage::pageHeaders() {
|
||||
return currentFrame()->property("headers").toStringList();
|
||||
QVariantMap WebPage::pageHeaders() {
|
||||
return currentFrame()->property("headers").toMap();
|
||||
}
|
||||
|
||||
QByteArray WebPage::body() {
|
||||
|
|
|
@ -47,7 +47,7 @@ class WebPage : public QWebPage {
|
|||
bool matchesWindowSelector(QString);
|
||||
void setFocus();
|
||||
void unsupportedContentFinishedReply(QNetworkReply *reply);
|
||||
QStringList pageHeaders();
|
||||
QVariantMap pageHeaders();
|
||||
QByteArray body();
|
||||
QString contentType();
|
||||
void mouseEvent(QEvent::Type type, const QPoint &position, Qt::MouseButton button);
|
||||
|
|
Loading…
Reference in New Issue