| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 IOS_WEB_PUBLIC_TEST_HTTP_SERVER_H_ | 5 #ifndef IOS_WEB_PUBLIC_TEST_HTTP_SERVER_H_ |
| 6 #define IOS_WEB_PUBLIC_TEST_HTTP_SERVER_H_ | 6 #define IOS_WEB_PUBLIC_TEST_HTTP_SERVER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // Starts the server on |port|. Returns true on success, false otherwise. | 68 // Starts the server on |port|. Returns true on success, false otherwise. |
| 69 // Must be called from the main thread. | 69 // Must be called from the main thread. |
| 70 bool StartOnPort(NSUInteger port); | 70 bool StartOnPort(NSUInteger port); |
| 71 // Stops the server and prevents it from accepting new requests. | 71 // Stops the server and prevents it from accepting new requests. |
| 72 // Must be called from the main thread. | 72 // Must be called from the main thread. |
| 73 void Stop(); | 73 void Stop(); |
| 74 // Returns true if the server is running. | 74 // Returns true if the server is running. |
| 75 // Must be called from the main thread. | 75 // Must be called from the main thread. |
| 76 bool IsRunning() const; | 76 bool IsRunning() const; |
| 77 | 77 |
| 78 // Returns the port that the server is running on. Thread Safe |
| 79 NSUInteger GetPort() const; |
| 80 |
| 78 // Adds a ResponseProvider. Takes ownership of the ResponseProvider. | 81 // Adds a ResponseProvider. Takes ownership of the ResponseProvider. |
| 79 // Note for using URLs inside of the |response_provider|: | 82 // Note for using URLs inside of the |response_provider|: |
| 80 // The HttpServer cannot run on default HTTP port 80, so URLs used in | 83 // The HttpServer cannot run on default HTTP port 80, so URLs used in |
| 81 // ResponseProviders must be converted at runtime after the HttpServer's port | 84 // ResponseProviders must be converted at runtime after the HttpServer's port |
| 82 // is determined. Please use |MakeUrl| to handle converting URLs. | 85 // is determined. Please use |MakeUrl| to handle converting URLs. |
| 83 // Must be called from the main thread. | 86 // Must be called from the main thread. |
| 84 void AddResponseProvider(std::unique_ptr<ResponseProvider> response_provider); | 87 void AddResponseProvider(std::unique_ptr<ResponseProvider> response_provider); |
| 85 // Removes the |response_provider|. Must be called from the main thread. | 88 // Removes the |response_provider|. Must be called from the main thread. |
| 86 void RemoveResponseProvider(ResponseProvider* response_provider); | 89 void RemoveResponseProvider(ResponseProvider* response_provider); |
| 87 // Removes all the response providers. Must be called from the main thread. | 90 // Removes all the response providers. Must be called from the main thread. |
| 88 void RemoveAllResponseProviders(); | 91 void RemoveAllResponseProviders(); |
| 89 | 92 |
| 90 private: | 93 private: |
| 91 // Initializes the server by registering for a GCDWebServer servlet. Must be | 94 // Initializes the server by registering for a GCDWebServer servlet. Must be |
| 92 // called from the main thread. | 95 // called from the main thread. |
| 93 void InitHttpServer(); | 96 void InitHttpServer(); |
| 94 HttpServer(); | 97 HttpServer(); |
| 95 ~HttpServer(); | 98 ~HttpServer(); |
| 96 | 99 |
| 97 // Sets the port that the server is running on. Thread Safe | 100 // Sets the port that the server is running on. Thread Safe |
| 98 void SetPort(NSUInteger port); | 101 void SetPort(NSUInteger port); |
| 99 // Returns the port that the server is running on. Thread Safe | |
| 100 NSUInteger GetPort() const; | |
| 101 | 102 |
| 102 // Creates a GURL that the server can service based on the |url| | 103 // Creates a GURL that the server can service based on the |url| |
| 103 // passed in. | 104 // passed in. |
| 104 // It does not rewrite URLs if the |url| can already be serviced by the | 105 // It does not rewrite URLs if the |url| can already be serviced by the |
| 105 // server. | 106 // server. |
| 106 // |url| must be a valid URL. Thread safe. | 107 // |url| must be a valid URL. Thread safe. |
| 107 GURL MakeUrlForHttpServer(const std::string& url) const; | 108 GURL MakeUrlForHttpServer(const std::string& url) const; |
| 108 | 109 |
| 109 // Returns the response provider that can handle the |request|. | 110 // Returns the response provider that can handle the |request|. |
| 110 // Note: No more than one reponse provider can handle the request. | 111 // Note: No more than one reponse provider can handle the request. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 124 // The list of providers to service a request. | 125 // The list of providers to service a request. |
| 125 std::vector<scoped_refptr<RefCountedResponseProviderWrapper>> providers_; | 126 std::vector<scoped_refptr<RefCountedResponseProviderWrapper>> providers_; |
| 126 DISALLOW_COPY_AND_ASSIGN(HttpServer); | 127 DISALLOW_COPY_AND_ASSIGN(HttpServer); |
| 127 }; | 128 }; |
| 128 | 129 |
| 129 } // namespace test | 130 } // namespace test |
| 130 } // namspace web | 131 } // namspace web |
| 131 | 132 |
| 132 #endif // IOS_WEB_PUBLIC_TEST_HTTP_SERVER_H_ | 133 #endif // IOS_WEB_PUBLIC_TEST_HTTP_SERVER_H_ |
| 133 | 134 |
| OLD | NEW |