| 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 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, represented as a concatenation of data | 19 // The payload for the request body, represented as a concatenation of data |
| 20 // streams. For HTTP requests, the method must be 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. | 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 | 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. | 30 // value is just a suggestion. The URLLoader may choose to ignore this value. |
| 31 uint32 response_body_buffer_size = 0; | 31 uint32 response_body_buffer_size = 0; |
| 32 | 32 |
| 33 // If set to true, then redirects will be automatically followed. Otherwise, | 33 // If set to true, then redirects will be automatically followed. Otherwise, |
| 34 // when a redirect is encounterd, FollowRedirect must be called to proceed. | 34 // when a redirect is encounterd, FollowRedirect must be called to proceed. |
| 35 bool auto_follow_redirects = false; | 35 bool auto_follow_redirects = false; |
| 36 | 36 |
| 37 // 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 |
| 38 // 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 |
| 39 // 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 |
| 40 // effect of forcing a full end-to-end fetch. | 40 // effect of forcing a full end-to-end fetch. |
| 41 bool bypass_cache = false; | 41 bool bypass_cache = false; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 struct URLResponse { | 44 struct URLResponse { |
| 45 // If the response resulted in a network level error, this field will be set. | 45 // If the response resulted in a network level error, this field will be set. |
| 46 NetworkError error; | 46 NetworkError? error; |
| 47 | 47 |
| 48 // The response body stream. Read from this data pipe to receive the bytes of | 48 // The response body stream. Read from this data pipe to receive the bytes of |
| 49 // response body. | 49 // response body. |
| 50 handle<data_pipe_consumer> body; | 50 handle<data_pipe_consumer> body; |
| 51 | 51 |
| 52 // The final URL of the response, after redirects have been followed. | 52 // The final URL of the response, after redirects have been followed. |
| 53 string url; | 53 string url; |
| 54 | 54 |
| 55 // The HTTP status code. 0 if not applicable. | 55 // The HTTP status code. 0 if not applicable. |
| 56 uint32 status_code; | 56 uint32 status_code; |
| 57 | 57 |
| 58 // The HTTP status line. | 58 // The HTTP status line. |
| 59 string status_line; | 59 string status_line; |
| 60 | 60 |
| 61 // The HTTP response headers. | 61 // The HTTP response headers. |
| 62 string[] headers; | 62 string[] headers; |
| 63 | 63 |
| 64 // The MIME type of the response body. | 64 // The MIME type of the response body. |
| 65 string mime_type; | 65 string mime_type; |
| 66 | 66 |
| 67 // The character set of the response body. | 67 // The character set of the response body. |
| 68 string charset; | 68 string charset; |
| 69 | 69 |
| 70 // These fields are set to non-NULL if this response corresponds to a | 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 | 71 // redirect. Call the |FollowRedirect| method on the URLLoader instance to |
| 72 // follow this redirect. | 72 // follow this redirect. |
| 73 string redirect_method; | 73 string? redirect_method; |
| 74 string redirect_url; | 74 string? redirect_url; |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 struct URLLoaderStatus { | 77 struct URLLoaderStatus { |
| 78 // If the loader has failed due to a network level error, this field will be | 78 // If the loader has failed due to a network level error, this field will be |
| 79 // set. | 79 // set. |
| 80 NetworkError error; | 80 NetworkError? error; |
| 81 | 81 |
| 82 // Set to true if the URLLoader is still working. Set to false once an error | 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 | 83 // is encountered or the response body is completely copied to the response |
| 84 // body stream. | 84 // body stream. |
| 85 bool is_loading; | 85 bool is_loading; |
| 86 | 86 |
| 87 // TODO(darin): Add further details about the stages of loading (e.g., | 87 // TODO(darin): Add further details about the stages of loading (e.g., |
| 88 // "resolving host") that happen prior to receiving bytes. | 88 // "resolving host") that happen prior to receiving bytes. |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 interface URLLoader { | 91 interface URLLoader { |
| 92 // Loads the given |request|, asynchronously producing |response|. Consult | 92 // Loads the given |request|, asynchronously producing |response|. Consult |
| 93 // |response| to determine if the request resulted in an error, was | 93 // |response| to determine if the request resulted in an error, was |
| 94 // redirected, or has a response body to be consumed. | 94 // redirected, or has a response body to be consumed. |
| 95 Start(URLRequest request) => (URLResponse response); | 95 Start(URLRequest request) => (URLResponse response); |
| 96 | 96 |
| 97 // 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, |
| 98 // then upon receiving an URLResponse with a non-NULL |redirect_url| field, | 98 // then upon receiving an URLResponse with a non-NULL |redirect_url| field, |
| 99 // |FollowRedirect| may be called to load the URL indicated by the redirect. | 99 // |FollowRedirect| may be called to load the URL indicated by the redirect. |
| 100 FollowRedirect() => (URLResponse response); | 100 FollowRedirect() => (URLResponse response); |
| 101 | 101 |
| 102 // Query status about the URLLoader. | 102 // Query status about the URLLoader. |
| 103 QueryStatus() => (URLLoaderStatus status); | 103 QueryStatus() => (URLLoaderStatus status); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 } | 106 } |
| OLD | NEW |