From 0cef38ee28df1de5ab60ae34bd729cf2846a59e2 Mon Sep 17 00:00:00 2001 From: Yutaka Hirano Date: Tue, 22 Nov 2016 17:59:29 +0900 Subject: [PATCH 1/6] 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();
    
    From 5fc6fb74086ba258171cd4b312f3164fb1a4e5fa Mon Sep 17 00:00:00 2001
    From: Yutaka Hirano 
    Date: Fri, 6 Jan 2017 21:33:10 +0900
    Subject: [PATCH 2/6] fix
    
    ---
     fetch.bs | 24 ++++++++++++++++++------
     1 file changed, 18 insertions(+), 6 deletions(-)
    
    diff --git a/fetch.bs b/fetch.bs
    index 5153ce150..430abc19e 100644
    --- a/fetch.bs
    +++ b/fetch.bs
    @@ -3073,9 +3073,12 @@ steps:
        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. +

    request is copied as httpRequest here as we need + to be able to add headers to httpRequest and read its body without + affecting request. Namely, rquest can be reused with redirects, + authentication, and proxy authentication. We copy rather than clone in order to reduce memory + consumption. In case request's body's source is + null, redirects and authentication will end up failing the fetch.

  • Let credentials flag be set if one of @@ -3098,10 +3101,10 @@ steps: `0`. -

  • If httpRequest's body is non-null, set +

  • If httpRequest's body is non-null and httpRequest's + body's source is non-null, then set contentLengthValue to httpRequest's body's total bytes, UTF-8 encoded. -

  • If contentLengthValue is non-null, append @@ -3109,7 +3112,7 @@ steps: httpRequest's header list. -

  • +
  • If contentLengthValue is non-null, httpRequest's keepalive flag is set, and contentLengthValue is greater than a user-agent-defined maximum, then return a network error. @@ -3119,6 +3122,11 @@ steps: a body, have a bounded size and are not allowed to stay alive indefinitely. +

  • If httpRequest's body is non-null and httpRequest's + body's source is null, then append + `Transfer-Encoding`/`chunked` to httpRequest's + header list. +

  • If httpRequest's referrer is a URL, then append `Referer`/httpRequest's referrer, serialized and UTF-8 encoded, to @@ -4849,6 +4857,10 @@ constructor must run these steps: {{Headers}} object. Rethrow any exception. +

  • If inputBody is non-null, inputBody's source is + null, and r's request's mode is neither + "same-origin" nor "cors", then throw a TypeError. +

  • Set r's request's body to inputBody. From 33d66ffbcf9cd4904d17ee6a76393b25f5d43b34 Mon Sep 17 00:00:00 2001 From: Yutaka Hirano Date: Fri, 6 Jan 2017 21:45:41 +0900 Subject: [PATCH 3/6] fix --- fetch.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fetch.bs b/fetch.bs index 430abc19e..2f17abc10 100644 --- a/fetch.bs +++ b/fetch.bs @@ -3075,7 +3075,7 @@ steps:

    request is copied as httpRequest here as we need to be able to add headers to httpRequest and read its body without - affecting request. Namely, rquest can be reused with redirects, + affecting request. Namely, request can be reused with redirects, authentication, and proxy authentication. We copy rather than clone in order to reduce memory consumption. In case request's body's source is null, redirects and authentication will end up failing the fetch. From e0ab78582ed83e80355c797da8371d4b28c1a377 Mon Sep 17 00:00:00 2001 From: Yutaka Hirano Date: Fri, 6 Jan 2017 22:25:21 +0900 Subject: [PATCH 4/6] fix --- fetch.bs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/fetch.bs b/fetch.bs index 2f17abc10..d762341b4 100644 --- a/fetch.bs +++ b/fetch.bs @@ -4857,9 +4857,17 @@ constructor must run these steps: {{Headers}} object. Rethrow any exception. -

  • If inputBody is non-null, inputBody's source is - null, and r's request's mode is neither - "same-origin" nor "cors", then throw a TypeError. +

  • +

    If inputBody is non-null and inputBody's source is + null, then run these substeps: + +

      +
    1. If r's request's mode is neither + "same-origin" nor "cors", then throw a TypeError. + +

    2. Set r's request's + use-CORS-preflight flag. +

  • Set r's request's body to inputBody. From f09599a3444a9961e612794b7e8f20f73c7a9cf9 Mon Sep 17 00:00:00 2001 From: Yutaka Hirano Date: Tue, 10 Jan 2017 22:35:21 +0900 Subject: [PATCH 5/6] fix --- fetch.bs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fetch.bs b/fetch.bs index d762341b4..72ab4d668 100644 --- a/fetch.bs +++ b/fetch.bs @@ -3488,6 +3488,10 @@ steps: therefore response represents both a response and an HTTP response here. +

    If request's header list contains + `Transfer-Encoding`/`chunked` and response is transferred + via HTTP/1.0 or older, then return a network error. +

    If the HTTP request results in a TLS client certificate dialog, run these substeps:

      From 19cec5f9ee37140b35d330c7098a860ffe7ab0c9 Mon Sep 17 00:00:00 2001 From: Yutaka Hirano Date: Wed, 11 Jan 2017 15:29:24 +0900 Subject: [PATCH 6/6] fix fix fix fix --- fetch.bs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fetch.bs b/fetch.bs index 72ab4d668..7152bb5f6 100644 --- a/fetch.bs +++ b/fetch.bs @@ -3121,12 +3121,6 @@ steps: allowed to outlive the environment settings object and contain a body, have a bounded size and are not allowed to stay alive indefinitely. - -
    1. If httpRequest's body is non-null and httpRequest's - body's source is null, then append - `Transfer-Encoding`/`chunked` to httpRequest's - header list. -

    2. If httpRequest's referrer is a URL, then append `Referer`/httpRequest's referrer, serialized and UTF-8 encoded, to @@ -3461,6 +3455,12 @@ steps:

    3. If connection is failure, return a network error. +

    4. If connection is not an HTTP/2 connection, request's + body is non-null, and request's body's + source is null, then append + `Transfer-Encoding`/`chunked` to request's + header list. +

    5. Let response be the result of making an HTTP request over connection using request with the following caveats: