• jrw's avatar
    Updated XHR API so call sites are more descriptive. · b6a2d047
    jrw authored
    This CL mainly converts from using positional parameters to a single
    struct, but there are various other changes as well.
    
    The functions corresponding to different HTTP methods have been
    eliminated, and the "doMethod" function has been renamed "start".
    Saving one parameter at each call site seemed like a poor tradeoff for
    having four functions that differ only in the HTTP method they use.
    
    The core logic of creating an XHR and arranging for the onDone
    function to be called has been factored out into a separate function,
    startInternal_.
    
    The "parameters" argument has been replaced by separate urlParams and
    content arguments.  This eliminates the need to heuristically decide
    what to do with the parmameters based on the HTTP method, and it
    allows URL parameters and body content to be included in the same
    call, a case which occurs in practice in host_controller.js.
    
    There are now three parameters for sepecifying different types of body
    content: textContent, formContent, and jsonContent.  They have
    different data types, and the formContent and jsonContent parameters
    implicitly set the Content-type header to the correct value.
    
    A new parameter, oauthToken, is a convenience for adding a
    correctly-formatted Authorization header.  This formatting was
    previously duplicated at five seperate call sites.
    
    The string "OAuth" in Authorization headers has been replaced with
    "Bearer". The OAuth 2 spec supports the use of "Bearer" but not
    "OAuth".
    
    There are no longer any instances where headers are specified
    explicitly, but the ability to do so still exists in the API.
    
    Finally, headers and urlParameters with the value null are accepted
    but not included in the HTTP request.  This simplifies the logic of
    the doRegisterHost function in host_controller.js.
    
    BUG=
    
    Review URL: https://codereview.chromium.org/945033002
    
    Cr-Commit-Position: refs/heads/master@{#318151}
    b6a2d047
xhr.js 6.1 KB