blob: edfecb7445e0fe8e41447a601551cb3432c815c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdio.h>
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "net/test/test_server.h"
static void PrintUsage() {
printf("run_testserver --doc-root=relpath [--http|--https|--ftp]\n");
printf("(NOTE: relpath should be relative to the 'src' directory)\n");
}
int main(int argc, const char* argv[]) {
base::AtExitManager at_exit_manager;
MessageLoopForIO message_loop;
// Process command line
CommandLine::Init(argc, argv);
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->GetSwitchCount() == 0 ||
command_line->HasSwitch("help")) {
PrintUsage();
return -1;
}
std::string protocol;
int port;
if (command_line->HasSwitch("https")) {
protocol = "https";
port = net::TestServerLauncher::kOKHTTPSPort;
} else if (command_line->HasSwitch("ftp")) {
protocol = "ftp";
port = net::kFTPDefaultPort;
} else {
protocol = "http";
port = net::kHTTPDefaultPort;
}
std::wstring doc_root = command_line->GetSwitchValue("doc-root");
if (doc_root.empty()) {
printf("Error: --doc-root must be specified\n");
PrintUsage();
return -1;
}
// Launch testserver
scoped_refptr<net::BaseTestServer> test_server;
if (protocol == "https") {
test_server = net::HTTPSTestServer::CreateGoodServer(doc_root);
} else if (protocol == "ftp") {
test_server = net::FTPTestServer::CreateServer(doc_root);
} else if (protocol == "http") {
test_server = net::HTTPTestServer::CreateServer(doc_root);
} else {
NOTREACHED();
}
printf("testserver running at %s://%s:%d (type ctrl+c to exit)\n",
protocol.c_str(),
net::TestServerLauncher::kHostName,
port);
message_loop.Run();
return 0;
}
|