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 #include "mojo/services/network/url_loader_impl.h" | 5 #include "mojo/services/network/url_loader_impl.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "mojo/common/common_type_converters.h" | 8 #include "mojo/common/common_type_converters.h" |
9 #include "mojo/services/network/network_context.h" | 9 #include "mojo/services/network/network_context.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
11 #include "net/base/load_flags.h" | 11 #include "net/base/load_flags.h" |
12 #include "net/http/http_response_headers.h" | 12 #include "net/http/http_response_headers.h" |
| 13 #include "net/url_request/redirect_info.h" |
13 | 14 |
14 namespace mojo { | 15 namespace mojo { |
15 namespace { | 16 namespace { |
16 | 17 |
17 const uint32_t kMaxReadSize = 64 * 1024; | 18 const uint32_t kMaxReadSize = 64 * 1024; |
18 | 19 |
19 // Generates an URLResponsePtr from the response state of a net::URLRequest. | 20 // Generates an URLResponsePtr from the response state of a net::URLRequest. |
20 URLResponsePtr MakeURLResponse(const net::URLRequest* url_request) { | 21 URLResponsePtr MakeURLResponse(const net::URLRequest* url_request) { |
21 URLResponsePtr response(URLResponse::New()); | 22 URLResponsePtr response(URLResponse::New()); |
22 response->url = String::From(url_request->url()); | 23 response->url = String::From(url_request->url()); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 if (!url_request_->status().is_success()) | 183 if (!url_request_->status().is_success()) |
183 status->error = MakeNetworkError(url_request_->status().error()); | 184 status->error = MakeNetworkError(url_request_->status().error()); |
184 } else { | 185 } else { |
185 status->is_loading = false; | 186 status->is_loading = false; |
186 } | 187 } |
187 // TODO(darin): Populate more status fields. | 188 // TODO(darin): Populate more status fields. |
188 callback.Run(status.Pass()); | 189 callback.Run(status.Pass()); |
189 } | 190 } |
190 | 191 |
191 void URLLoaderImpl::OnReceivedRedirect(net::URLRequest* url_request, | 192 void URLLoaderImpl::OnReceivedRedirect(net::URLRequest* url_request, |
192 const GURL& new_url, | 193 const net::RedirectInfo& redirect_info, |
193 bool* defer_redirect) { | 194 bool* defer_redirect) { |
194 DCHECK(url_request == url_request_.get()); | 195 DCHECK(url_request == url_request_.get()); |
195 DCHECK(url_request->status().is_success()); | 196 DCHECK(url_request->status().is_success()); |
196 | 197 |
197 if (auto_follow_redirects_) | 198 if (auto_follow_redirects_) |
198 return; | 199 return; |
199 | 200 |
200 // Send the redirect response to the client, allowing them to inspect it and | 201 // Send the redirect response to the client, allowing them to inspect it and |
201 // optionally follow the redirect. | 202 // optionally follow the redirect. |
202 *defer_redirect = true; | 203 *defer_redirect = true; |
203 | 204 |
204 URLResponsePtr response = MakeURLResponse(url_request); | 205 URLResponsePtr response = MakeURLResponse(url_request); |
205 response->redirect_method = | 206 response->redirect_method = redirect_info.method; |
206 net::URLRequest::ComputeMethodForRedirect(url_request->method(), | 207 response->redirect_url = String::From(redirect_info.url); |
207 response->status_code); | |
208 response->redirect_url = String::From(new_url); | |
209 | 208 |
210 SendResponse(response.Pass()); | 209 SendResponse(response.Pass()); |
211 } | 210 } |
212 | 211 |
213 void URLLoaderImpl::OnResponseStarted(net::URLRequest* url_request) { | 212 void URLLoaderImpl::OnResponseStarted(net::URLRequest* url_request) { |
214 DCHECK(url_request == url_request_.get()); | 213 DCHECK(url_request == url_request_.get()); |
215 | 214 |
216 if (!url_request->status().is_success()) { | 215 if (!url_request->status().is_success()) { |
217 SendError(url_request->status().error(), callback_); | 216 SendError(url_request->status().error(), callback_); |
218 callback_ = Callback<void(URLResponsePtr)>(); | 217 callback_ = Callback<void(URLResponsePtr)>(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 if (completed_synchronously) { | 321 if (completed_synchronously) { |
323 base::MessageLoop::current()->PostTask( | 322 base::MessageLoop::current()->PostTask( |
324 FROM_HERE, | 323 FROM_HERE, |
325 base::Bind(&URLLoaderImpl::ReadMore, weak_ptr_factory_.GetWeakPtr())); | 324 base::Bind(&URLLoaderImpl::ReadMore, weak_ptr_factory_.GetWeakPtr())); |
326 } else { | 325 } else { |
327 ReadMore(); | 326 ReadMore(); |
328 } | 327 } |
329 } | 328 } |
330 | 329 |
331 } // namespace mojo | 330 } // namespace mojo |
OLD | NEW |