| // Copyright 2015 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| [DartPackage="mojo_services"] |
| module mojo; |
| |
| import "mojo/public/interfaces/network/url_request.mojom"; |
| import "mojo/public/interfaces/network/url_response.mojom"; |
| |
| // Factory for |URLLoaderInterceptor|. The factory is called once per URLLoader |
| // and will be associated to it. |
| interface URLLoaderInterceptorFactory { |
| Create(URLLoaderInterceptor& interceptor); |
| }; |
| |
| // An |URLLoaderInterceptor| is associated to a single URLLoader. It will be |
| // able to intercept requests sent to the URLLoader and transform these or |
| // directly respond to it. It will also intercept responses and transform them |
| // or ask the network to continue with another request instead. |
| // In case of redirect, the behavior is the following: |
| // - If in the request |auto_follow_redirects| is true, the interceptor doesn't |
| // have access to any of the intermediate request(s) or response(s). |
| // Otherwise, it has access to intermediate responses as they are sent to the |
| // client and it is also notified when the client asks to follow a redirect. |
| interface URLLoaderInterceptor { |
| // Intercept a request before it is sent to the network. This method can |
| // transform the request by returning the new requests to consider, or |
| // respond to the request itself by returning a response. |
| InterceptRequest(URLRequest request) => |
| (URLLoaderInterceptorResponse response); |
| |
| // Intercept |URLLoader.FollowRedirect()| calls. This method can either |
| // return null to let the call through, return a request to change the |
| // redirect, or respond to the redirect itself by returning a response. |
| InterceptFollowRedirect() => (URLLoaderInterceptorResponse? response); |
| |
| // Intercept a response before it is sent to the loader client. This method |
| // can transform the response by returning the new response to send, ask |
| // the loader to load a new request instead by returning the request to load, |
| // or if the response is a redirect, follow it by returning null. |
| InterceptResponse(URLResponse response) => |
| (URLLoaderInterceptorResponse? response); |
| }; |
| |
| // Response for the intercept methods. One and only one of the two fields |
| // must be set. If |request| is set, the url loader will execute the request. |
| // If |response| is set, the url loader will send it to its client. It is the |
| // responsibility of the interceptor not to create infinite loops. |
| // TODO(qsr): Change this to an union. |
| struct URLLoaderInterceptorResponse { |
| URLRequest? request; |
| URLResponse? response; |
| }; |