Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(823)

Side by Side Diff: mojo/services/public/interfaces/network/url_loader.mojom

Issue 373373002: Mojo: Refactor URLLoader interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes per review Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 import "mojo/services/public/interfaces/network/network_error.mojom" 5 import "mojo/services/public/interfaces/network/network_error.mojom"
6 6
7 module mojo { 7 module mojo {
8 8
9 struct URLRequest { 9 struct URLRequest {
10 // The URL to load. 10 // The URL to load.
11 string url; 11 string url;
12 12
13 // The HTTP method if applicable. 13 // The HTTP method if applicable.
14 string method = "GET"; 14 string method = "GET";
15 15
16 // Additional HTTP request headers. 16 // Additional HTTP request headers.
17 string[] headers; 17 string[] headers;
18 18
19 // The payload for the request body. For HTTP requests, the method must be 19 // The payload for the request body, represented as a concatenation of data
20 // set to "POST" or "PUT". 20 // streams. For HTTP requests, the method must be set to "POST" or "PUT".
21 handle<data_pipe_consumer> body; 21 handle<data_pipe_consumer>[] body;
22 22
23 // The number of bytes to be read from |body|. A Content-Length header of 23 // The number of bytes to be read from |body|. A Content-Length header of
24 // this value will be sent. Set to -1 if length is unknown, which will cause 24 // this value will be sent. Set to -1 if length is unknown, which will cause
25 // |body| to be uploaded using a chunked encoding. 25 // |body| to be uploaded using a chunked encoding.
26 int64 body_length = 0; 26 int64 body_length = 0;
27 27
28 // The buffer size of the data pipe returned in URLResponse's |body| member.
29 // A value of 0 indicates that the default buffer size should be used. This
30 // value is just a suggestion. The URLLoader may choose to ignore this value.
31 uint32 response_body_buffer_size = 0;
32
28 // If set to true, then redirects will be automatically followed. Otherwise, 33 // If set to true, then redirects will be automatically followed. Otherwise,
29 // when a redirect is encounterd, FollowRedirect must be called to proceed. 34 // when a redirect is encounterd, FollowRedirect must be called to proceed.
30 bool auto_follow_redirects = false; 35 bool auto_follow_redirects = false;
31 36
32 // If set to true, then the HTTP request will bypass the local cache and will 37 // If set to true, then the HTTP request will bypass the local cache and will
33 // have a 'Cache-Control: nocache' header added in that causes any proxy 38 // have a 'Cache-Control: nocache' header added in that causes any proxy
34 // servers to also not satisfy the request from their cache. This has the 39 // servers to also not satisfy the request from their cache. This has the
35 // effect of forcing a full end-to-end fetch. 40 // effect of forcing a full end-to-end fetch.
36 bool bypass_cache = false; 41 bool bypass_cache = false;
37 }; 42 };
38 43
39 struct URLResponse { 44 struct URLResponse {
45 // If the response resulted in a network level error, this field will be set.
46 NetworkError error;
47
48 // The response body stream. Read from this data pipe to receive the bytes of
49 // response body.
50 handle<data_pipe_consumer> body;
51
40 // The final URL of the response, after redirects have been followed. 52 // The final URL of the response, after redirects have been followed.
41 string url; 53 string url;
42 54
43 // The HTTP status code. 0 if not applicable. 55 // The HTTP status code. 0 if not applicable.
44 uint32 status_code; 56 uint32 status_code;
45 57
46 // The HTTP status line. 58 // The HTTP status line.
47 string status_line; 59 string status_line;
48 60
49 // The HTTP response headers. 61 // The HTTP response headers.
50 string[] headers; 62 string[] headers;
51 63
52 // The MIME type of the response body. 64 // The MIME type of the response body.
53 string mime_type; 65 string mime_type;
54 66
55 // The character set of the response body. 67 // The character set of the response body.
56 string charset; 68 string charset;
69
70 // These fields are set to non-NULL if this response corresponds to a
71 // redirect. Call the |FollowRedirect| method on the URLLoader instance to
72 // follow this redirect.
73 string redirect_method;
74 string redirect_url;
57 }; 75 };
58 76
59 [Client=URLLoaderClient] 77 struct URLLoaderStatus {
78 // If the loader has failed due to a network level error, this field will be
79 // set.
80 NetworkError error;
81
82 // Set to true if the URLLoader is still working. Set to false once an error
83 // is encountered or the response body is completely copied to the response
84 // body stream.
85 bool is_loading;
86
87 // TODO(darin): Add further details about the stages of loading (e.g.,
88 // "resolving host") that happen prior to receiving bytes.
89 };
90
60 interface URLLoader { 91 interface URLLoader {
61 // Start loading the given |request|. When available, the response body will 92 // Loads the given |request|, asynchronously producing |response|. Consult
62 // be copied to |response_body_stream|. 93 // |response| to determine if the request resulted in an error, was
63 // 94 // redirected, or has a response body to be consumed.
64 // The client's |OnReceivedResponse| method will run when response meta data 95 Start(URLRequest request) => (URLResponse response);
65 // becomes available, or if a redirect response is encountered and
66 // |auto_follow_redirects| is false, the client's |OnRecievedRedirect| method
67 // will called instead.
68 //
69 // NOTE: You may observe data being pushed to |response_body_stream| before
70 // you receive |OnReceivedResponse|.
71 Start(URLRequest request, handle<data_pipe_producer> response_body_stream);
72 96
73 // If the request passed to |Start| had |auto_follow_redirects| set to false, 97 // If the request passed to |Start| had |auto_follow_redirects| set to false,
74 // then upon receiving a redirect, |OnReceivedRedirect| will be called. To 98 // then upon receiving an URLResponse with a non-NULL |redirect_url| field,
75 // follow the indicated redirect, call the |FollowRedirect| method. 99 // |FollowRedirect| may be called to load the URL indicated by the redirect.
76 FollowRedirect(); 100 FollowRedirect() => (URLResponse response);
77 };
78 101
79 interface URLLoaderClient { 102 // Query status about the URLLoader.
80 // This method is called when a redirect is encountered, provided the 103 QueryStatus() => (URLLoaderStatus status);
81 // request's |auto_follow_redirects| attribute was set to false.
82 OnReceivedRedirect(URLResponse response, string new_url, string new_method);
83
84 // This method is called when response meta data becomes available.
85 OnReceivedResponse(URLResponse response);
86
87 // This method is called when a network level error is encountered. This can
88 // happen before or after OnReceivedResponse, but cannot happen after
89 // OnReceivedEndOfResponseBody.
90 OnReceivedError(NetworkError error);
91
92 // This method is called when the response body has been successfully
93 // downloaded and copied in its entirety to |response_body_stream|.
94 //
95 // NOTE: Because |response_body_stream| is limited in size, this event may be
96 // delayed until |response_body_stream| is consumed.
97 OnReceivedEndOfResponseBody();
98 }; 104 };
99 105
100 } 106 }
OLDNEW
« no previous file with comments | « mojo/services/public/interfaces/navigation/navigation.mojom ('k') | mojo/shell/dynamic_service_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698