| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ | 5 #ifndef NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ |
| 6 #define NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ | 6 #define NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "net/socket/tcp_listen_socket.h" | 18 #include "net/socket/tcp_listen_socket.h" |
| 19 | 19 |
| 20 namespace base { |
| 21 class FilePath; |
| 22 } |
| 23 |
| 20 namespace net { | 24 namespace net { |
| 21 namespace test_server { | 25 namespace test_server { |
| 22 | 26 |
| 23 class HttpConnection; | 27 class HttpConnection; |
| 24 class HttpResponse; | 28 class HttpResponse; |
| 25 struct HttpRequest; | 29 struct HttpRequest; |
| 26 | 30 |
| 27 // This class is required to be able to have composition instead of inheritance, | 31 // This class is required to be able to have composition instead of inheritance, |
| 28 class HttpListenSocket : public TCPListenSocket { | 32 class HttpListenSocket : public TCPListenSocket { |
| 29 public: | 33 public: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 const GURL& base_url() const { return base_url_; } | 104 const GURL& base_url() const { return base_url_; } |
| 101 | 105 |
| 102 // Returns a URL to the server based on the given relative URL, which | 106 // Returns a URL to the server based on the given relative URL, which |
| 103 // should start with '/'. For example: GetURL("/path?query=foo") => | 107 // should start with '/'. For example: GetURL("/path?query=foo") => |
| 104 // http://127.0.0.1:<port>/path?query=foo. | 108 // http://127.0.0.1:<port>/path?query=foo. |
| 105 GURL GetURL(const std::string& relative_url) const; | 109 GURL GetURL(const std::string& relative_url) const; |
| 106 | 110 |
| 107 // Returns the port number used by the server. | 111 // Returns the port number used by the server. |
| 108 int port() const { return port_; } | 112 int port() const { return port_; } |
| 109 | 113 |
| 114 // Registers request handler which serves files from |directory|. |
| 115 // For instance, a request to "/foo.html" is served by "foo.html" under |
| 116 // |directory|. Files under sub directories are also handled in the same way |
| 117 // (i.e. "/foo/bar.html" is served by "foo/bar.html" under |directory|). |
| 118 void ServeFilesFromDirectory(const base::FilePath& directory); |
| 119 |
| 110 // The most general purpose method. Any request processing can be added using | 120 // The most general purpose method. Any request processing can be added using |
| 111 // this method. Takes ownership of the object. The |callback| is called | 121 // this method. Takes ownership of the object. The |callback| is called |
| 112 // on UI thread. | 122 // on UI thread. |
| 113 void RegisterRequestHandler(const HandleRequestCallback& callback); | 123 void RegisterRequestHandler(const HandleRequestCallback& callback); |
| 114 | 124 |
| 115 private: | 125 private: |
| 116 // Initializes and starts the server. If initialization succeeds, Starts() | 126 // Initializes and starts the server. If initialization succeeds, Starts() |
| 117 // will return true. | 127 // will return true. |
| 118 void InitializeOnIOThread(); | 128 void InitializeOnIOThread(); |
| 119 | 129 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 163 |
| 154 base::ThreadChecker thread_checker_; | 164 base::ThreadChecker thread_checker_; |
| 155 | 165 |
| 156 DISALLOW_COPY_AND_ASSIGN(EmbeddedTestServer); | 166 DISALLOW_COPY_AND_ASSIGN(EmbeddedTestServer); |
| 157 }; | 167 }; |
| 158 | 168 |
| 159 } // namespace test_servers | 169 } // namespace test_servers |
| 160 } // namespace net | 170 } // namespace net |
| 161 | 171 |
| 162 #endif // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ | 172 #endif // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ |
| OLD | NEW |