• When curl sends 100-continue


    When curl sends 100-continue

    When sending a POST request with curl it sometimes automatically adds an Expect: 100-continue header. The following summarizes under which conditions curl/libcurl adds this header.

    Background

    The Expect: 100-continue header is specified in HTTP 1.1 and allows the server to acknowledge or reject a POST/PUT request immediately after the headers are send but before the client starts sending potentially large amounts of actual data (body of the request). Thus, a conforming client must then wait for a HTTP/1.1 100 Continue before sending the data. This scheme is advantageous for larger POST/PUT requests since in the case of rejection the client and server don't waste their time with superfluous network communication.

    Curl Logic

    Curl doesn't touch the 'Expect' header if it is explicitly set.

    Otherwise, curl automatically sets it, if either

    By default, curl waits up to 1 second for a reply to the 100-continue expectation. This timeout is configurable (e.g. via --expect100-timeout SECS).

    Disabling Expect Logic

    The expect logic can easily be disabled via setting the Expect: header to the empty string.

    For example, on the command line via:

    $ curl -H 'Expect:' -H 'Transfer-Encoding: ...' -H 'Content-Type: ...' 
        --data-binary '@mediumfile' http://example.org/archive -v
    

    With libcurl the header can be configured via setting CURLOPT_HTTPHEADER using curl_easy_setopt().

    Disabling the expect logic saves an additional network round-trip and is thus a good idea when the request isn't extremely large and the probability for rejection is low.

    Testing

    For testing, the expect logic can also be explicitly turned on, e.g.:

    $ curl -H 'Expect: 100-continue' -H 'Content-Type: text/csv+x-lz4' 
        -H 'Transfer-Encoding: chunked' --data-binary ' ' 
        http://example.org/archive -v
    

    Posted by Georg Sauthoff on Sat 28 January 2017 in network. Tags: curl, http.

  • 相关阅读:
    js变量声明提前
    03通讯录(Block传值)
    03-Block
    03通讯录(搭建编辑界面)
    03通讯录(代理解耦)
    03通讯录(逆传)
    03通讯录
    源码0604-06-掌握-大文件断点下载(断点下载)
    源码0604-05-程序不死
    源码0604-02-了解-网页开发
  • 原文地址:https://www.cnblogs.com/liujx2019/p/13332005.html
Copyright © 2020-2023  润新知