Skip to content

Commit

Permalink
Fixing IE to correctly set Content-length header for HTTP responses
Browse files Browse the repository at this point in the history
Not setting this header properly is a protocol violation, and strict
HTTP clients (like .NET's HttpWebRequest/HttpWebResponse) will reject
such an HTTP response for the 1.1 version of the HTTP protocol.
  • Loading branch information
jimevans committed Dec 20, 2018
1 parent 0a7b9a2 commit 1787a9a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 17 deletions.
8 changes: 4 additions & 4 deletions cpp/iedriver/IEDriver.rc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,141,0,3
PRODUCTVERSION 3,141,0,3
FILEVERSION 3,141,0,4
PRODUCTVERSION 3,141,0,4
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -68,12 +68,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Software Freedom Conservancy"
VALUE "FileDescription", "Driver library for the IE driver"
VALUE "FileVersion", "3.141.0.3"
VALUE "FileVersion", "3.141.0.4"
VALUE "InternalName", "IEDriver.dll"
VALUE "LegalCopyright", "Copyright (C) 2018"
VALUE "OriginalFilename", "IEDriver.dll"
VALUE "ProductName", "Selenium WebDriver"
VALUE "ProductVersion", "3.141.0.3"
VALUE "ProductVersion", "3.141.0.4"
END
END
BLOCK "VarFileInfo"
Expand Down
35 changes: 34 additions & 1 deletion cpp/iedriverserver/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,43 @@ available via the project downloads page. Changes in "revision" field indicate
private releases checked into the prebuilts directory of the source tree, but
not made generally available on the downloads page.

v3.141.0.4
==========
* Fixed to correctly set Content-length header for HTTP responses.
Not setting this header properly is a protocol violation, and strict
HTTP clients (like .NET's HttpWebRequest/HttpWebResponse) will reject
such an HTTP response for the 1.1 version of the HTTP protocol.
* Reduced JavaScript errors during findElement(s). In most cases, executing
JavaScript is an atomic action for the IE driver. However, in the off
chance that there is a page refresh during the execution of JavaScript,
converting the result of the script to a JSON object for serialization
might cause an error, in which case we should return the appropriate
error to the caller. One place, however, where this might be common is
executing findElement(s) across a page navigation. This change makes the
driver return the proper error in the post-processing of a script
execution. It also recognizes the findElement(s) case, ignoring
JavaScript errors in finding elements, and returning the proper structure
(an empty list or a "no such element" error) in its place. This lets
things like explicit waits retry the find, which may succeed once the
page navigation has completed and the DOM available for querying again.
* Tweaked obscured element algorithm. The algorithm used by the IE driver
to detect obscured elements checks the value of the pointer-events CSS
computed style property. This property can have valid values of "auto"
and "none" which affect whether to consider an element "obscured."
However, the property can also contain other values for SVG elements.
If the element in question is not an SVG element, then values other
than "none" and "auto" must be ignored, and the element considered not
to obscure the target element.
* Fixed compile warnings.

v3.141.0.3
==========
* Updated Civetweb dependency to version 1.11.
* Modified IE driver to no longer always sent Connection: close header.
* Modified IE driver to no longer always send Connection: close header.
This is a potentially destablizing change, as the driver now should
correctly use keep-alive for HTTP requests and responses. While this
should not matter, the driver has not ever executed true with keep-
alive connections, so care should be used.

v3.141.0.2
==========
Expand Down
8 changes: 4 additions & 4 deletions cpp/iedriverserver/IEDriverServer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,141,0,3
PRODUCTVERSION 3,141,0,3
FILEVERSION 3,141,0,4
PRODUCTVERSION 3,141,0,4
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -68,12 +68,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Software Freedom Conservancy"
VALUE "FileDescription", "Command line server for the IE driver"
VALUE "FileVersion", "3.141.0.3"
VALUE "FileVersion", "3.141.0.4"
VALUE "InternalName", "IEDriverServer.exe"
VALUE "LegalCopyright", "Copyright (C) 2018"
VALUE "OriginalFilename", "IEDriverServer.exe"
VALUE "ProductName", "Selenium WebDriver"
VALUE "ProductVersion", "3.141.0.3"
VALUE "ProductVersion", "3.141.0.4"
END
END
BLOCK "VarFileInfo"
Expand Down
Binary file modified cpp/prebuilt/Win32/Release/IEDriverServer.exe
Binary file not shown.
Binary file modified cpp/prebuilt/x64/Release/IEDriverServer.exe
Binary file not shown.
24 changes: 16 additions & 8 deletions cpp/webdriver-server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -520,15 +520,17 @@ void Server::SendHttpOk(struct mg_connection* connection,
const std::string& content_type) {
LOG(TRACE) << "Entering Server::SendHttpOk";

std::string body_to_send = body + "\r\n";

std::ostringstream out;
out << "HTTP/1.1 200 OK\r\n"
<< "Content-Length: " << strlen(body.c_str()) << "\r\n"
<< "Content-Length: " << strlen(body_to_send.c_str()) << "\r\n"
<< "Content-Type: " << content_type << "; charset=UTF-8\r\n"
<< "Cache-Control: no-cache\r\n"
<< "Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept\r\n"
<< "Accept-Ranges: bytes\r\n\r\n";
if (strcmp(request_info->request_method, "HEAD") != 0) {
out << body << "\r\n";
out << body_to_send;
}

mg_write(connection, out.str().c_str(), out.str().size());
Expand All @@ -539,15 +541,17 @@ void Server::SendHttpBadRequest(struct mg_connection* const connection,
const std::string& body) {
LOG(TRACE) << "Entering Server::SendHttpBadRequest";

std::string body_to_send = body + "\r\n";

std::ostringstream out;
out << "HTTP/1.1 400 Bad Request\r\n"
<< "Content-Length: " << strlen(body.c_str()) << "\r\n"
<< "Content-Length: " << strlen(body_to_send.c_str()) << "\r\n"
<< "Content-Type: application/json; charset=UTF-8\r\n"
<< "Cache-Control: no-cache\r\n"
<< "Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept\r\n"
<< "Accept-Ranges: bytes\r\n\r\n";
if (strcmp(request_info->request_method, "HEAD") != 0) {
out << body << "\r\n";
out << body_to_send;
}

mg_printf(connection, "%s", out.str().c_str());
Expand All @@ -558,15 +562,17 @@ void Server::SendHttpInternalError(struct mg_connection* connection,
const std::string& body) {
LOG(TRACE) << "Entering Server::SendHttpInternalError";

std::string body_to_send = body + "\r\n";

std::ostringstream out;
out << "HTTP/1.1 500 Internal Server Error\r\n"
<< "Content-Length: " << strlen(body.c_str()) << "\r\n"
<< "Content-Length: " << strlen(body_to_send.c_str()) << "\r\n"
<< "Content-Type: application/json; charset=UTF-8\r\n"
<< "Cache-Control: no-cache\r\n"
<< "Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept\r\n"
<< "Accept-Ranges: bytes\r\n\r\n";
if (strcmp(request_info->request_method, "HEAD") != 0) {
out << body << "\r\n";
out << body_to_send;
}

mg_write(connection, out.str().c_str(), out.str().size());
Expand All @@ -577,15 +583,17 @@ void Server::SendHttpNotFound(struct mg_connection* const connection,
const std::string& body) {
LOG(TRACE) << "Entering Server::SendHttpNotFound";

std::string body_to_send = body + "\r\n";

std::ostringstream out;
out << "HTTP/1.1 404 Not Found\r\n"
<< "Content-Length: " << strlen(body.c_str()) << "\r\n"
<< "Content-Length: " << strlen(body_to_send.c_str()) << "\r\n"
<< "Content-Type: application/json; charset=UTF-8\r\n"
<< "Cache-Control: no-cache\r\n"
<< "Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept\r\n"
<< "Accept-Ranges: bytes\r\n\r\n";
if (strcmp(request_info->request_method, "HEAD") != 0) {
out << body << "\r\n";
out << body_to_send;
}

mg_printf(connection, "%s", out.str().c_str());
Expand Down

0 comments on commit 1787a9a

Please sign in to comment.