Home | History | Annotate | Download | only in network
      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
      3 // found in the LICENSE file.
      4 
      5 import "network_error.mojom"
      6 
      7 module mojo {
      8 
      9 struct URLRequest {
     10   // The URL to load.
     11   string url;
     12 
     13   // The HTTP method if applicable.
     14   string method = "GET";
     15 
     16   // Additional HTTP request headers.
     17   string[] headers;
     18 
     19   // The payload for the request body. For HTTP requests, the method must be
     20   // set to "POST" or "PUT".
     21   handle<data_pipe_consumer> body;
     22 
     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
     25   // |body| to be uploaded using a chunked encoding.
     26   int64 body_length = 0;
     27 
     28   // If set to true, then redirects will be automatically followed. Otherwise,
     29   // when a redirect is encounterd, FollowRedirect must be called to proceed.
     30   bool auto_follow_redirects = false;
     31 
     32   // 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
     34   // servers to also not satisfy the request from their cache.  This has the
     35   // effect of forcing a full end-to-end fetch.
     36   bool bypass_cache = false;
     37 };
     38 
     39 struct URLResponse {
     40   // The final URL of the response, after redirects have been followed.
     41   string url;
     42 
     43   // The HTTP status code. 0 if not applicable.
     44   uint32 status_code;
     45 
     46   // The HTTP status line.
     47   string status_line;
     48 
     49   // The HTTP response headers.
     50   string[] headers;
     51 };
     52 
     53 [Client=URLLoaderClient]
     54 interface URLLoader {
     55   // Start loading the given |request|. When available, the response body will
     56   // be copied to |response_body_stream|.
     57   //
     58   // The client's |OnReceivedResponse| method will run when response meta data
     59   // becomes available, or if a redirect response is encountered and
     60   // |auto_follow_redirects| is false, the client's |OnRecievedRedirect| method
     61   // will called instead.
     62   //
     63   // NOTE: You may observe data being pushed to |response_body_stream| before
     64   // you receive |OnReceivedResponse|.
     65   Start(URLRequest request, handle<data_pipe_producer> response_body_stream);
     66 
     67   // If the request passed to |Start| had |auto_follow_redirects| set to false,
     68   // then upon receiving a redirect, |OnReceivedRedirect| will be called. To
     69   // follow the indicated redirect, call the |FollowRedirect| method.
     70   FollowRedirect();
     71 };
     72 
     73 interface URLLoaderClient {
     74   // This method is called when a redirect is encountered, provided the
     75   // request's |auto_follow_redirects| attribute was set to false.
     76   OnReceivedRedirect(URLResponse response, string new_url, string new_method);
     77 
     78   // This method is called when response meta data becomes available.
     79   OnReceivedResponse(URLResponse response);
     80 
     81   // This method is called when a network level error is encountered. This can
     82   // happen before or after OnReceivedResponse, but cannot happen after
     83   // OnReceivedEndOfResponseBody.
     84   OnReceivedError(NetworkError error);
     85 
     86   // This method is called when the response body has been successfully
     87   // downloaded and copied in its entirety to |response_body_stream|.
     88   //
     89   // NOTE: Because |response_body_stream| is limited in size, this event may be
     90   // delayed until |response_body_stream| is consumed.
     91   OnReceivedEndOfResponseBody();
     92 };
     93 
     94 }
     95