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.

  • 相关阅读:
    JS使用及技巧.
    文件上传
    闭包
    文件拖拽上传
    zTree简单使用
    call apply bind
    jquery中操作jQuery对象的eq和get的差别与用法--操作前台显示之利器
    Cocos2d-x 文件路径下文件的读写
    Linux程序设计学习笔记----多线程编程基础概念与基本操作
    不easy查找Bug
  • 原文地址:https://www.cnblogs.com/liujx2019/p/13332005.html
Copyright © 2011-2022 走看看