- Revision
- 233516
- Author
- [email protected]
- Date
- 2018-07-05 05:41:08 -0700 (Thu, 05 Jul 2018)
Log Message
[GTK][WPE] Add --host option to WebDriver process
https://bugs.webkit.org/show_bug.cgi?id=187288
Reviewed by Žan Doberšek.
We currently allow to pass a port number and the server always listens for connections on localhost. We should
allow to optionally pass a host IP address to be able to use WebDriver remotely.
* HTTPServer.h:
* WebDriverService.cpp:
(WebDriver::printUsageStatement): Update usage to include --host option.
(WebDriver::WebDriverService::run): Parse --host option and pass it to HTTPServer::listen().
* soup/HTTPServerSoup.cpp:
(WebDriver::soupServerListen): Helper to call soup_server_listen_local(), soup_server_listen_all() or
soup_server_listen() depending on the given host.
(WebDriver::HTTPServer::listen): Use soupServerListen() helper.
Modified Paths
Diff
Modified: trunk/Source/WebDriver/ChangeLog (233515 => 233516)
--- trunk/Source/WebDriver/ChangeLog 2018-07-05 11:42:00 UTC (rev 233515)
+++ trunk/Source/WebDriver/ChangeLog 2018-07-05 12:41:08 UTC (rev 233516)
@@ -1,3 +1,22 @@
+2018-07-05 Carlos Garcia Campos <[email protected]>
+
+ [GTK][WPE] Add --host option to WebDriver process
+ https://bugs.webkit.org/show_bug.cgi?id=187288
+
+ Reviewed by Žan Doberšek.
+
+ We currently allow to pass a port number and the server always listens for connections on localhost. We should
+ allow to optionally pass a host IP address to be able to use WebDriver remotely.
+
+ * HTTPServer.h:
+ * WebDriverService.cpp:
+ (WebDriver::printUsageStatement): Update usage to include --host option.
+ (WebDriver::WebDriverService::run): Parse --host option and pass it to HTTPServer::listen().
+ * soup/HTTPServerSoup.cpp:
+ (WebDriver::soupServerListen): Helper to call soup_server_listen_local(), soup_server_listen_all() or
+ soup_server_listen() depending on the given host.
+ (WebDriver::HTTPServer::listen): Use soupServerListen() helper.
+
2018-06-24 Carlos Garcia Campos <[email protected]>
Unreviewed. Fix WebDriver tests after r233077.
Modified: trunk/Source/WebDriver/HTTPServer.h (233515 => 233516)
--- trunk/Source/WebDriver/HTTPServer.h 2018-07-05 11:42:00 UTC (rev 233515)
+++ trunk/Source/WebDriver/HTTPServer.h 2018-07-05 12:41:08 UTC (rev 233516)
@@ -57,7 +57,7 @@
explicit HTTPServer(HTTPRequestHandler&);
~HTTPServer() = default;
- bool listen(unsigned port);
+ bool listen(const std::optional<String>& host, unsigned port);
void disconnect();
private:
Modified: trunk/Source/WebDriver/WebDriverService.cpp (233515 => 233516)
--- trunk/Source/WebDriver/WebDriverService.cpp 2018-07-05 11:42:00 UTC (rev 233515)
+++ trunk/Source/WebDriver/WebDriverService.cpp 2018-07-05 12:41:08 UTC (rev 233516)
@@ -45,8 +45,9 @@
static void printUsageStatement(const char* programName)
{
printf("Usage: %s options\n", programName);
- printf(" -h, --help Prints this help message\n");
+ printf(" -h, --help Prints this help message\n");
printf(" -p <port>, --port=<port> Port number the driver will use\n");
+ printf(" --host=<host> Host IP the driver will use, or either 'local' or 'all' (default: 'local')");
printf("\n");
}
@@ -53,6 +54,7 @@
int WebDriverService::run(int argc, char** argv)
{
String portString;
+ std::optional<String> host;
for (int i = 1 ; i < argc; ++i) {
const char* arg = argv[i];
if (!strcmp(arg, "-h") || !strcmp(arg, "--help")) {
@@ -74,6 +76,12 @@
portString = String(arg + portStrLength);
continue;
}
+
+ static const unsigned hostStrLength = strlen("--host=");
+ if (!strncmp(arg, "--host=", hostStrLength) && !host) {
+ host = String(arg + hostStrLength);
+ continue;
+ }
}
if (portString.isNull()) {
@@ -90,7 +98,7 @@
RunLoop::initializeMainRunLoop();
- if (!m_server.listen(port))
+ if (!m_server.listen(host, port))
return EXIT_FAILURE;
RunLoop::run();
Modified: trunk/Source/WebDriver/soup/HTTPServerSoup.cpp (233515 => 233516)
--- trunk/Source/WebDriver/soup/HTTPServerSoup.cpp 2018-07-05 11:42:00 UTC (rev 233515)
+++ trunk/Source/WebDriver/soup/HTTPServerSoup.cpp 2018-07-05 12:41:08 UTC (rev 233516)
@@ -32,11 +32,29 @@
namespace WebDriver {
-bool HTTPServer::listen(unsigned port)
+static bool soupServerListen(SoupServer* server, const std::optional<String>& host, unsigned port, GError** error)
{
+ static const auto options = static_cast<SoupServerListenOptions>(0);
+ if (!host || host.value() == "local")
+ return soup_server_listen_local(server, port, options, error);
+
+ if (host.value() == "all")
+ return soup_server_listen_all(server, port, options, error);
+
+ GRefPtr<GSocketAddress> address = adoptGRef(g_inet_socket_address_new_from_string(host.value().utf8().data(), port));
+ if (!address) {
+ g_set_error(error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Invalid host IP address '%s'", host.value().utf8().data());
+ return false;
+ }
+
+ return soup_server_listen(server, address.get(), options, error);
+}
+
+bool HTTPServer::listen(const std::optional<String>& host, unsigned port)
+{
m_soupServer = adoptGRef(soup_server_new(SOUP_SERVER_SERVER_HEADER, "WebKitWebDriver", nullptr));
GUniqueOutPtr<GError> error;
- if (!soup_server_listen_local(m_soupServer.get(), port, static_cast<SoupServerListenOptions>(0), &error.outPtr())) {
+ if (!soupServerListen(m_soupServer.get(), host, port, &error.outPtr())) {
WTFLogAlways("Failed to start HTTP server at port %u: %s", port, error->message);
return false;
}