From 0cef38ee28df1de5ab60ae34bd729cf2846a59e2 Mon Sep 17 00:00:00 2001 From: Yutaka Hirano Date: Tue, 22 Nov 2016 17:59:29 +0900 Subject: [PATCH] Add upload streams (a Request with a ReadableStream body) Basic test: https://github.com/w3c/web-platform-tests/pull/4362. More tests are expected to be written as part of the implementation effort. Further work: #441. Fixes #88. --- fetch.bs | 92 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 74 insertions(+), 18 deletions(-) diff --git a/fetch.bs b/fetch.bs index 17e833703..5153ce150 100644 --- a/fetch.bs +++ b/fetch.bs @@ -15,7 +15,7 @@ Markup Shorthands: css off !Commits: [SNAPSHOT-LINK] !Commits: @fetchstandard !Translation (non-normative): 日本語 -Translate IDs: typedefdef-bodyinit bodyinit,typedefdef-responsebodyinit responsebodyinit,dictdef-requestinit requestinit,typedefdef-requestinfo requestinfo,enumdef-requesttype requesttype,enumdef-requestdestination requestdestination,enumdef-requestmode requestmode,enumdef-requestcredentials requestcredentials,enumdef-requestcache requestcache,enumdef-requestredirect requestredirect,dictdef-responseinit responseinit,enumdef-responsetype responsetype +Translate IDs: typedefdef-bodyinit bodyinit,dictdef-requestinit requestinit,typedefdef-requestinfo requestinfo,enumdef-requesttype requesttype,enumdef-requestdestination requestdestination,enumdef-requestmode requestmode,enumdef-requestcredentials requestcredentials,enumdef-requestcache requestcache,enumdef-requestredirect requestredirect,dictdef-responseinit responseinit,enumdef-responsetype responsetype @@ -571,13 +571,16 @@ user-agent-defined value for the

A body consists of:

A body body is said to be @@ -2984,6 +2987,10 @@ in addition to HTTP fetch above. includes credentials, then return a network error. +

  • If actualResponse's status is not 303, + request's body is non-null, and request's + body's source is null, then return a network error. +

  • If CORS flag is set and actualResponse's location URL @@ -3008,6 +3015,15 @@ in addition to HTTP fetch above. to `GET` and request's body to null. +

  • +

    If request's body is non-null, then set request's + body to the first part of extracting + request's body's source. + +

    request's body's source's + nullity has already been checked. The extracting operation cannot + throw as it was called for the same source before. +

  • Append actualResponse's location URL to request's url list. @@ -3035,17 +3051,31 @@ steps: authentication-fetch flag.

      +
    1. Let httpRequest be null. + +

    2. If request's window is "no-window" and + request's redirect mode is "error", then set + httpRequest to request. +

    3. -

      Let httpRequest be request if - request's window is "no-window" - and request's redirect mode is - "error", and the result of cloning - request otherwise. +

      Otherwise, run these substeps: -

      A request is typically cloned as it needs to be possible to - add headers and read its - body without affecting request. As - request is reused with redirects, authentication, and proxy authentication. +

        +
      1. Set httpRequest to a copy of request except for its + body. + +

      2. Let body be request's body. + +

      3. Set httpRequest's body to body. + +

      4. If body is non-null, then set request's body to a + new body whose stream is null and whose source is + body's source. +

      + +

      Here we do not clone request in order + to reduce memory consumption. request can be reused with redirects, authentication, + and proxy authentication.

    4. Let credentials flag be set if one of @@ -3326,6 +3356,22 @@ steps:

    5. Needs testing: multiple `WWW-Authenticate` headers, missing, parsing issues. +

    6. +

      If request's body is non-null, then run these subsubsteps: + +

        +
      1. If request's body's source is null, + then return a network error. + +

      2. +

        Set request's body to the first part of + extracting request's body's + source. + +

        The extracting operation cannot + throw as it was called for the same source before. +

      +
    7. If request's use-URL-credentials flag is unset or @@ -4184,9 +4230,7 @@ method, when invoked, must run these steps:

      Body mixin

      -typedef (Blob or BufferSource or FormData or URLSearchParams or USVString) BodyInit;
      -
      -typedef (BodyInit or ReadableStream) ResponseBodyInit;
      +typedef (Blob or BufferSource or FormData or URLSearchParams or ReadableStream or USVString) BodyInit;

      To extract a body and a `Content-Type` value from @@ -4199,7 +4243,9 @@ typedef (BodyInit or ReadableStream) ResponseBodyInit;

    8. Let Content-Type be null. -

    9. Let action be null. +

    10. Let action be null. + +

    11. Let source be null.

    12. Switch on object's type: @@ -4212,6 +4258,8 @@ typedef (BodyInit or ReadableStream) ResponseBodyInit;

      If object's {{Blob/type}} attribute is not the empty byte sequence, set Content-Type to its value. +

      Set source to object. +

      BufferSource

      Enqueue a Uint8Array object @@ -4220,6 +4268,8 @@ typedef (BodyInit or ReadableStream) ResponseBodyInit; stream. If that threw an exception, error stream with that exception. +

      Set source to object. +

      {{FormData}}

      Set action to an action that runs the @@ -4232,6 +4282,8 @@ typedef (BodyInit or ReadableStream) ResponseBodyInit; multipart/form-data boundary string generated by the multipart/form-data encoding algorithm. +

      Set source to object. +

      {{URLSearchParams}}

      Set action to an action that runs the @@ -4243,12 +4295,16 @@ typedef (BodyInit or ReadableStream) ResponseBodyInit;

      Set Content-Type to `application/x-www-form-urlencoded;charset=UTF-8`. +

      Set source to object. +

      USVString

      Set action to an action that runs UTF-8 encode on object.

      Set Content-Type to `text/plain;charset=UTF-8`. +

      Set source to object. +

      {{ReadableStream}}

      Set stream to object. @@ -4272,8 +4328,8 @@ typedef (BodyInit or ReadableStream) ResponseBodyInit; close stream.

    -
  • Let body be a body whose - stream is stream. +

  • Let body be a body whose stream is + stream and whose source is source.

  • Return body and Content-Type. @@ -4914,7 +4970,7 @@ run these steps:

    Response class

    -
    [Constructor(optional ResponseBodyInit? body = null, optional ResponseInit init),
    +
    [Constructor(optional BodyInit? body = null, optional ResponseInit init),
      Exposed=(Window,Worker)]
     interface Response {
       [NewObject] static Response error();