<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>82202</bug_id>
          
          <creation_ts>2012-03-26 07:06:55 -0700</creation_ts>
          <short_desc>Make XHR POST and PUT Content-Length sending behavior explicit on XHR level</short_desc>
          <delta_ts>2012-04-02 02:05:25 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore JavaScript</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Dominik Röttsches (drott)">d-r</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>danw</cc>
    
    <cc>gustavo</cc>
    
    <cc>rakuco</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>587695</commentid>
    <comment_count>0</comment_count>
    <who name="Dominik Röttsches (drott)">d-r</who>
    <bug_when>2012-03-26 07:06:55 -0700</bug_when>
    <thetext>Following the discussion and observations on bug 82036, I suggest to align XmlHttpRequest&apos;s behavior for sending Content-Length with other browser implementations. 

All tested browser implementations (FF, Opera, IE, Chromium) send a zero Content-Length Header on an empty (send()) as well as on a zero-length body (send(&quot;&quot;)). However, WebKit does not make that explicit in the XHR code and leaves it to the HTTP backend which leads to a variation in tests results.

So, WebKit should send a zero Content-Length header in POST/PUT cases for empty as well as zero-length http body.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>587857</commentid>
    <comment_count>1</comment_count>
      <attachid>133840</attachid>
    <who name="Dominik Röttsches (drott)">d-r</who>
    <bug_when>2012-03-26 10:05:47 -0700</bug_when>
    <thetext>Created attachment 133840
XHR Sending Content Length for zero-sized and empty POST &amp; PUT

When I implement a change to XMLHttpRequest like in this patch adding the Content-Length: header for empty and zero sized bodies and POST &amp; PUT case in method createRequest() I run into a couple of failures for
http/tests/xmlhttprequest/access-control-*.html which tell me:
&quot;Request header field Content-Length is not allowed by Access-Control-Allow-Headers.&quot;

So is this something that we know need to circumvent on the XHR level / exempt from the header checking? (If so, any suggestions how?)

Or does this mean we&apos;re back to a point where it&apos;s better to implement that change at the HTTP level?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>587910</commentid>
    <comment_count>2</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2012-03-26 11:00:38 -0700</bug_when>
    <thetext>The rule is that the engine can send whatever headers it deems correct, but JavaScript code can only change most header fields if explicitly allowed by a CORS reply from server. And some header fields cannot be set at all, regardless of CORS.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>588737</commentid>
    <comment_count>3</comment_count>
    <who name="Dominik Röttsches (drott)">d-r</who>
    <bug_when>2012-03-27 04:12:10 -0700</bug_when>
    <thetext>Thanks, Alexey. The architectural problem I am facing here is that any header manipulation inside XHR code that is relevant for CORS is detected by the security checks that are invoked downstream of
http://trac.webkit.org/browser/trunk/Source/WebCore/xml/XMLHttpRequest.cpp#L728 (ThreadableLoader::create, then CrossOriginPreflightResultCacheItem::allowsCrossOriginHeaders)

So, in my current understanding, we would either need some kind of dangerous and ugly circumvention, like
ThreadableLoaderOptions options.crossOriginRequestPolicy = UseAccessControlButAllowMeToSetContentLength;

or go back to the initial approach and intercept empty and non-zero POST/PUT requests below the CORS/DocumentThreadable loader level on the ResourceRequest or  the specific libsoup backend level. (The other HTTP backends seem to behave correctly already.)

Maybe I miss something - so other suggestions are very welcome. Otherwise at this point I would say, let&apos;s fix it at the libsoup level. What do you think, Dan, Alexey?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>592126</commentid>
    <comment_count>4</comment_count>
    <who name="Dan Winship">danw</who>
    <bug_when>2012-03-30 06:40:03 -0700</bug_when>
    <thetext>If the organization of the XHR code makes this difficult to do at the XHR level then sure, do it in the soup backend.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>593262</commentid>
    <comment_count>5</comment_count>
    <who name="Dominik Röttsches (drott)">d-r</who>
    <bug_when>2012-04-02 02:05:25 -0700</bug_when>
    <thetext>Back to the soup level, will provide patch in bug 82036.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>133840</attachid>
            <date>2012-03-26 10:05:47 -0700</date>
            <delta_ts>2012-03-26 10:05:47 -0700</delta_ts>
            <desc>XHR Sending Content Length for zero-sized and empty POST &amp; PUT</desc>
            <filename>XHR_CL.patch</filename>
            <type>text/plain</type>
            <size>974</size>
            <attacher name="Dominik Röttsches (drott)">d-r</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XZWJDb3JlL3htbC9YTUxIdHRwUmVxdWVzdC5jcHAgYi9Tb3Vy
Y2UvV2ViQ29yZS94bWwvWE1MSHR0cFJlcXVlc3QuY3BwCmluZGV4IDcxMjIwMGMuLjA2ODliOTMg
MTAwNjQ0Ci0tLSBhL1NvdXJjZS9XZWJDb3JlL3htbC9YTUxIdHRwUmVxdWVzdC5jcHAKKysrIGIv
U291cmNlL1dlYkNvcmUveG1sL1hNTEh0dHBSZXF1ZXN0LmNwcApAQCAtNzAzLDYgKzcwMywxNSBA
QCB2b2lkIFhNTEh0dHBSZXF1ZXN0OjpjcmVhdGVSZXF1ZXN0KEV4Y2VwdGlvbkNvZGUmIGVjKQog
ICAgICAgICByZXF1ZXN0LnNldEhUVF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