OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/automation/url_request_mock_http_job.h" | 5 #include "chrome/browser/automation/url_request_mock_http_job.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 const FilePath& file_path) | 61 const FilePath& file_path) |
62 : URLRequestFileJob(request, file_path) { } | 62 : URLRequestFileJob(request, file_path) { } |
63 | 63 |
64 // Public virtual version. | 64 // Public virtual version. |
65 void URLRequestMockHTTPJob::GetResponseInfo(net::HttpResponseInfo* info) { | 65 void URLRequestMockHTTPJob::GetResponseInfo(net::HttpResponseInfo* info) { |
66 // Forward to private const version. | 66 // Forward to private const version. |
67 GetResponseInfoConst(info); | 67 GetResponseInfoConst(info); |
68 } | 68 } |
69 | 69 |
70 // Private const version. | 70 // Private const version. |
71 void URLRequestMockHTTPJob::GetResponseInfoConst(net::HttpResponseInfo* info) co
nst { | 71 void URLRequestMockHTTPJob::GetResponseInfoConst( |
| 72 net::HttpResponseInfo* info) const { |
72 std::wstring header_file = file_path_.ToWStringHack() + kMockHeaderFileSuffix; | 73 std::wstring header_file = file_path_.ToWStringHack() + kMockHeaderFileSuffix; |
73 std::string raw_headers; | 74 std::string raw_headers; |
74 if (!file_util::ReadFileToString(header_file, &raw_headers)) | 75 if (!file_util::ReadFileToString(header_file, &raw_headers)) |
75 return; | 76 return; |
76 | 77 |
77 // ParseRawHeaders expects \0 to end each header line. | 78 // ParseRawHeaders expects \0 to end each header line. |
78 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); | 79 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); |
79 info->headers = new net::HttpResponseHeaders(raw_headers); | 80 info->headers = new net::HttpResponseHeaders(raw_headers); |
80 } | 81 } |
81 | 82 |
82 bool URLRequestMockHTTPJob::GetMimeType(std::string* mime_type) const { | 83 bool URLRequestMockHTTPJob::GetMimeType(std::string* mime_type) const { |
83 net::HttpResponseInfo info; | 84 net::HttpResponseInfo info; |
84 GetResponseInfoConst(&info); | 85 GetResponseInfoConst(&info); |
85 return info.headers && info.headers->GetMimeType(mime_type); | 86 return info.headers && info.headers->GetMimeType(mime_type); |
86 } | 87 } |
87 | 88 |
88 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) { | 89 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) { |
89 net::HttpResponseInfo info; | 90 net::HttpResponseInfo info; |
90 GetResponseInfo(&info); | 91 GetResponseInfo(&info); |
91 return info.headers && info.headers->GetCharset(charset); | 92 return info.headers && info.headers->GetCharset(charset); |
92 } | 93 } |
OLD | NEW |