OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 [DartPackage="mojo_services"] | 5 [DartPackage="mojo_services"] |
6 module mojo; | 6 module mojo; |
7 | 7 |
8 import "mojo/public/interfaces/network/url_request.mojom"; | 8 import "mojo/public/interfaces/network/url_request.mojom"; |
9 import "mojo/public/interfaces/network/url_response.mojom"; | 9 import "mojo/public/interfaces/network/url_response.mojom"; |
10 | 10 |
11 // Factory for |URLLoaderInterceptor|. The factory is called once per URLLoader | 11 // Factory for |URLLoaderInterceptor|. The factory is called once per URLLoader |
12 // and will be associated to it. | 12 // and will be associated to it. |
13 interface URLLoaderInterceptorFactory { | 13 interface URLLoaderInterceptorFactory { |
14 Create(URLLoaderInterceptor& interceptor); | 14 Create(URLLoaderInterceptor& interceptor); |
15 }; | 15 }; |
16 | 16 |
17 // An |URLLoaderInterceptor| is associated to a single URLLoader. It will be | 17 // An |URLLoaderInterceptor| is associated to a single URLLoader. It will be |
18 // able to intercept requests sent to the URLLoader and transform these or | 18 // able to intercept requests sent to the URLLoader and transform these or |
19 // directly respond to it. It will also intercept responses and transform them | 19 // directly respond to it. It will also intercept responses and transform them |
20 // or ask the network to continue with another request instead. | 20 // or ask the network to continue with another request instead. |
21 // In case of redirect, the behavior is the following: | 21 // In case of redirect, the behavior is the following: |
22 // - If in the request |auto_follow_redirects| is true, the interceptor doesn't | 22 // - If in the request |auto_follow_redirects| is true, the interceptor doesn't |
23 // have access to any of the intermediate request(s) or response(s). | 23 // have access to any of the intermediate request(s) or response(s). |
24 // Otherwise, it has access to intermediate responses as they are sent to the | 24 // Otherwise, it has access to intermediate responses as they are sent to the |
25 // client and it is also notified when the client asks to follow a redirect. | 25 // client and it is also notified when the client asks to follow a redirect. |
26 interface URLLoaderInterceptor { | 26 interface URLLoaderInterceptor { |
27 // Intercept a request before it is sent to the network. This method can | 27 // Intercept a request before it is sent to the network. This method can |
28 // transform the request by returning the new requests to consider, or | 28 // transform the request by returning the new requests to consider, or |
29 // respond to the request itself by returning a response. | 29 // respond to the request itself by returning a response. |
30 InterceptRequest(URLRequest request) => | 30 InterceptRequest(URLRequest request) => (URLLoaderInterceptorResponse response
); |
31 (URLLoaderInterceptorResponse response); | |
32 | 31 |
33 // Intercept |URLLoader.FollowRedirect()| calls. This method can either | 32 // Intercept |URLLoader.FollowRedirect()| calls. This method can either |
34 // return null to let the call through, return a request to change the | 33 // return null to let the call through, return a request to change the |
35 // redirect, or respond to the redirect itself by returning a response. | 34 // redirect, or respond to the redirect itself by returning a response. |
36 InterceptFollowRedirect() => (URLLoaderInterceptorResponse? response); | 35 InterceptFollowRedirect() => (URLLoaderInterceptorResponse? response); |
37 | 36 |
38 // Intercept a response before it is sent to the loader client. This method | 37 // Intercept a response before it is sent to the loader client. This method |
39 // can transform the response by returning the new response to send, ask | 38 // can transform the response by returning the new response to send, ask |
40 // the loader to load a new request instead by returning the request to load, | 39 // the loader to load a new request instead by returning the request to load, |
41 // or if the response is a redirect, follow it by returning null. | 40 // or if the response is a redirect, follow it by returning null. |
42 InterceptResponse(URLResponse response) => | 41 InterceptResponse(URLResponse response) => (URLLoaderInterceptorResponse? resp
onse); |
43 (URLLoaderInterceptorResponse? response); | |
44 }; | 42 }; |
45 | 43 |
46 // Response for the intercept methods. One and only one of the two fields | 44 // Response for the intercept methods. One and only one of the two fields |
47 // must be set. If |request| is set, the url loader will execute the request. | 45 // must be set. If |request| is set, the url loader will execute the request. |
48 // If |response| is set, the url loader will send it to its client. It is the | 46 // If |response| is set, the url loader will send it to its client. It is the |
49 // responsibility of the interceptor not to create infinite loops. | 47 // responsibility of the interceptor not to create infinite loops. |
50 // TODO(qsr): Change this to an union. | 48 // TODO(qsr): Change this to an union. |
51 struct URLLoaderInterceptorResponse { | 49 struct URLLoaderInterceptorResponse { |
52 URLRequest? request; | 50 URLRequest? request; |
53 URLResponse? response; | 51 URLResponse? response; |
54 }; | 52 }; |
OLD | NEW |