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 module mojo; | 5 module mojo; |
6 | 6 |
7 import "network/public/interfaces/http_message.mojom"; | 7 import "mojo/public/interfaces/network/network_error.mojom"; |
8 import "network/public/interfaces/network_error.mojom"; | 8 import "mojo/public/interfaces/network/url_request.mojom"; |
9 | 9 import "mojo/public/interfaces/network/url_response.mojom"; |
10 struct URLRequest { | |
11 // The URL to load. | |
12 string url; | |
13 | |
14 // The HTTP method if applicable. | |
15 string method = "GET"; | |
16 | |
17 // Additional HTTP request headers. | |
18 array<HttpHeader>? headers; | |
19 | |
20 // The payload for the request body, represented as a concatenation of data | |
21 // streams. For HTTP requests, the method must be set to "POST" or "PUT". | |
22 array<handle<data_pipe_consumer>>? body; | |
23 | |
24 // The buffer size of the data pipe returned in URLResponse's |body| member. | |
25 // A value of 0 indicates that the default buffer size should be used. This | |
26 // value is just a suggestion. The URLLoader may choose to ignore this value. | |
27 uint32 response_body_buffer_size = 0; | |
28 | |
29 // If set to true, then redirects will be automatically followed. Otherwise, | |
30 // when a redirect is encounterd, FollowRedirect must be called to proceed. | |
31 bool auto_follow_redirects = false; | |
32 | |
33 // If set to true, then the HTTP request will bypass the local cache and will | |
34 // have a 'Cache-Control: nocache' header added in that causes any proxy | |
35 // servers to also not satisfy the request from their cache. This has the | |
36 // effect of forcing a full end-to-end fetch. | |
37 bool bypass_cache = false; | |
38 }; | |
39 | |
40 struct URLResponse { | |
41 // If the response resulted in a network level error, this field will be set. | |
42 NetworkError? error; | |
43 | |
44 // The response body stream. Read from this data pipe to receive the bytes of | |
45 // response body. | |
46 handle<data_pipe_consumer>? body; | |
47 | |
48 // The final URL of the response, after redirects have been followed. | |
49 string? url; | |
50 | |
51 // The HTTP status code. 0 if not applicable. | |
52 uint32 status_code; | |
53 | |
54 // The HTTP status line. | |
55 string? status_line; | |
56 | |
57 // The HTTP response headers. | |
58 array<HttpHeader>? headers; | |
59 | |
60 // The MIME type of the response body. | |
61 string? mime_type; | |
62 | |
63 // The character set of the response body. | |
64 string? charset; | |
65 | |
66 // These fields are set to non-NULL if this response corresponds to a | |
67 // redirect. Call the |FollowRedirect| method on the URLLoader instance to | |
68 // follow this redirect. | |
69 string? redirect_method; | |
70 string? redirect_url; | |
71 string? redirect_referrer; | |
72 }; | |
73 | 10 |
74 struct URLLoaderStatus { | 11 struct URLLoaderStatus { |
75 // If the loader has failed due to a network level error, this field will be | 12 // If the loader has failed due to a network level error, this field will be |
76 // set. | 13 // set. |
77 NetworkError? error; | 14 NetworkError? error; |
78 | 15 |
79 // Set to true if the URLLoader is still working. Set to false once an error | 16 // Set to true if the URLLoader is still working. Set to false once an error |
80 // is encountered or the response body is completely copied to the response | 17 // is encountered or the response body is completely copied to the response |
81 // body stream. | 18 // body stream. |
82 bool is_loading; | 19 bool is_loading; |
83 | 20 |
84 // TODO(darin): Add further details about the stages of loading (e.g., | 21 // TODO(darin): Add further details about the stages of loading (e.g., |
85 // "resolving host") that happen prior to receiving bytes. | 22 // "resolving host") that happen prior to receiving bytes. |
86 }; | 23 }; |
87 | 24 |
88 interface URLLoader { | 25 interface URLLoader { |
89 // Loads the given |request|, asynchronously producing |response|. Consult | 26 // Loads the given |request|, asynchronously producing |response|. Consult |
90 // |response| to determine if the request resulted in an error, was | 27 // |response| to determine if the request resulted in an error, was |
91 // redirected, or has a response body to be consumed. | 28 // redirected, or has a response body to be consumed. |
92 Start(URLRequest request) => (URLResponse response); | 29 Start(URLRequest request) => (URLResponse response); |
93 | 30 |
94 // If the request passed to |Start| had |auto_follow_redirects| set to false, | 31 // If the request passed to |Start| had |auto_follow_redirects| set to false, |
95 // then upon receiving an URLResponse with a non-NULL |redirect_url| field, | 32 // then upon receiving an URLResponse with a non-NULL |redirect_url| field, |
96 // |FollowRedirect| may be called to load the URL indicated by the redirect. | 33 // |FollowRedirect| may be called to load the URL indicated by the redirect. |
97 FollowRedirect() => (URLResponse response); | 34 FollowRedirect() => (URLResponse response); |
98 | 35 |
99 // Query status about the URLLoader. | 36 // Query status about the URLLoader. |
100 QueryStatus() => (URLLoaderStatus status); | 37 QueryStatus() => (URLLoaderStatus status); |
101 }; | 38 }; |
OLD | NEW |