zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    Jenkins修改用户密码及权限
    Selenium知识点小结
    解析图形验证码登录系统
    Pywinauto实现电脑客户端有道云签到领空间
    Python冒泡排序
    LoadRunner12常用函数
    GIT教程笔记
    LoadRunner 关联
    搭建自动化测试框架Python3+Selenium
    SSH免密从A服务器登录进B服务器,重启B服务器的tomcat
  • 原文地址:https://www.cnblogs.com/liujx2019/p/13332005.html
Copyright © 2011-2022 走看看