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 #include "net/test/embedded_test_server/embedded_test_server.h" | 5 #include "net/test/embedded_test_server/embedded_test_server.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 not_found_response.PassAs<HttpResponse>()); | 189 not_found_response.PassAs<HttpResponse>()); |
190 } | 190 } |
191 | 191 |
192 // Drop the connection, since we do not support multiple requests per | 192 // Drop the connection, since we do not support multiple requests per |
193 // connection. | 193 // connection. |
194 connections_.erase(connection->socket_.get()); | 194 connections_.erase(connection->socket_.get()); |
195 delete connection; | 195 delete connection; |
196 } | 196 } |
197 | 197 |
198 GURL EmbeddedTestServer::GetURL(const std::string& relative_url) const { | 198 GURL EmbeddedTestServer::GetURL(const std::string& relative_url) const { |
| 199 DCHECK(Started()) << "You must start the server first."; |
199 DCHECK(StartsWithASCII(relative_url, "/", true /* case_sensitive */)) | 200 DCHECK(StartsWithASCII(relative_url, "/", true /* case_sensitive */)) |
200 << relative_url; | 201 << relative_url; |
201 return base_url_.Resolve(relative_url); | 202 return base_url_.Resolve(relative_url); |
202 } | 203 } |
203 | 204 |
204 void EmbeddedTestServer::ServeFilesFromDirectory( | 205 void EmbeddedTestServer::ServeFilesFromDirectory( |
205 const base::FilePath& directory) { | 206 const base::FilePath& directory) { |
206 RegisterRequestHandler(base::Bind(&HandleFileRequest, directory)); | 207 RegisterRequestHandler(base::Bind(&HandleFileRequest, directory)); |
207 } | 208 } |
208 | 209 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 base::RunLoop run_loop; | 279 base::RunLoop run_loop; |
279 if (!io_thread_->PostTaskAndReply(FROM_HERE, closure, run_loop.QuitClosure())) | 280 if (!io_thread_->PostTaskAndReply(FROM_HERE, closure, run_loop.QuitClosure())) |
280 return false; | 281 return false; |
281 run_loop.Run(); | 282 run_loop.Run(); |
282 | 283 |
283 return true; | 284 return true; |
284 } | 285 } |
285 | 286 |
286 } // namespace test_server | 287 } // namespace test_server |
287 } // namespace net | 288 } // namespace net |
OLD | NEW |