summaryrefslogtreecommitdiffstats
path: root/chrome/test/webdriver/http_response.cc
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-18 02:58:31 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-18 02:58:31 +0000
commit726f32537a7ee9d8a6abf06771c5d569306f0a07 (patch)
treee5c9f24e05dc30c8dda9a0d4178bf048140b5b71 /chrome/test/webdriver/http_response.cc
parent9dd5cbb7c5356f02253e854732ba9f6b49c534ef (diff)
downloadchromium_src-726f32537a7ee9d8a6abf06771c5d569306f0a07.zip
chromium_src-726f32537a7ee9d8a6abf06771c5d569306f0a07.tar.gz
chromium_src-726f32537a7ee9d8a6abf06771c5d569306f0a07.tar.bz2
Fix ChromeDriver flakiness with the C# webdriver bindings.
Since keep-alive was disabled in r142538, C# webdriver tests have been failing occassionally saying no response was sent from chromedriver. This is because the .NET HttpWebRequest throws an exception when the server closes a connection without specifying Connection:close. This was reproducible on slower machines. This change refactors the http response process to funnel all responses through WriteHttpResponse, which adds the Connection:close header when appropriate. BUG=chromedriver:121 TEST=none TBR=ben Review URL: https://chromiumcodereview.appspot.com/10827362 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152227 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/webdriver/http_response.cc')
-rw-r--r--chrome/test/webdriver/http_response.cc67
1 files changed, 45 insertions, 22 deletions
diff --git a/chrome/test/webdriver/http_response.cc b/chrome/test/webdriver/http_response.cc
index 6bbe4a9..d07a6b3 100644
--- a/chrome/test/webdriver/http_response.cc
+++ b/chrome/test/webdriver/http_response.cc
@@ -15,14 +15,26 @@ const int HttpResponse::kNoContent = 204;
const int HttpResponse::kSeeOther = 303;
const int HttpResponse::kNotModified = 304;
const int HttpResponse::kBadRequest = 400;
+const int HttpResponse::kForbidden = 403;
const int HttpResponse::kNotFound = 404;
const int HttpResponse::kMethodNotAllowed = 405;
const int HttpResponse::kInternalServerError = 500;
+const int HttpResponse::kNotImplemented = 501;
+
+namespace {
+
+const char* kContentLengthHeader = "content-length";
+
+} // namespace
HttpResponse::HttpResponse()
: status_(kOk) {
}
+HttpResponse::HttpResponse(int status)
+ : status_(status) {
+}
+
HttpResponse::~HttpResponse() {
}
@@ -69,26 +81,10 @@ void HttpResponse::ClearHeaders() {
headers_.clear();
}
-void HttpResponse::UpdateHeader(const std::string& name,
- const std::string& new_value) {
- RemoveHeader(name);
- AddHeader(name, new_value);
-}
-
void HttpResponse::SetMimeType(const std::string& mime_type) {
UpdateHeader("Content-Type", mime_type);
}
-void HttpResponse::SetBody(const std::string& data) {
- SetBody(data.data(), data.length());
-}
-
-void HttpResponse::SetBody(const char* const data, size_t length) {
- data_ = std::string(data, length);
- UpdateHeader("Content-Length",
- base::StringPrintf("%"PRIuS"", data_.length()));
-}
-
std::string HttpResponse::GetReasonPhrase() const {
switch (status_) {
case kOk:
@@ -101,17 +97,42 @@ std::string HttpResponse::GetReasonPhrase() const {
return "Not Modified";
case kBadRequest:
return "Bad Request";
+ case kForbidden:
+ return "Forbidden";
case kNotFound:
return "Not Found";
case kMethodNotAllowed:
return "Method Not Allowed";
case kInternalServerError:
return "Internal Server Error";
+ case kNotImplemented:
+ return "Not Implemented";
default:
return "Unknown";
}
}
+void HttpResponse::GetData(std::string* data) const {
+ *data += base::StringPrintf("HTTP/1.1 %d %s\r\n",
+ status_, GetReasonPhrase().c_str());
+
+ typedef HttpResponse::HeaderMap::const_iterator HeaderIter;
+ for (HeaderIter header = headers_.begin(); header != headers_.end();
+ ++header) {
+ *data += header->first + ":" + header->second + "\r\n";
+ }
+ std::string length;
+ if (!GetHeader(kContentLengthHeader, &length)) {
+ *data += base::StringPrintf(
+ "%s:%"PRIuS"\r\n",
+ kContentLengthHeader, body_.length());
+ }
+ *data += "\r\n";
+
+ if (body_.length())
+ *data += body_;
+}
+
int HttpResponse::status() const {
return status_;
}
@@ -120,16 +141,18 @@ void HttpResponse::set_status(int status) {
status_ = status;
}
-const HttpResponse::HeaderMap* HttpResponse::headers() const {
- return &headers_;
+const std::string& HttpResponse::body() const {
+ return body_;
}
-const char* HttpResponse::data() const {
- return data_.data();
+void HttpResponse::set_body(const std::string& body) {
+ body_ = body;
}
-size_t HttpResponse::length() const {
- return data_.length();
+void HttpResponse::UpdateHeader(const std::string& name,
+ const std::string& new_value) {
+ RemoveHeader(name);
+ AddHeader(name, new_value);
}
} // namespace webdriver