Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: f6b4cabc8a081b394102aa9760f55f33c41b6b91
Ticket: 6afa947d1a92aacecdc4e681741d006b63da4e94
http::geturl : Missing Content-Length header for POST requests
User & Date: droll on 2017-06-05 20:09:20
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    HTTP POST requests require a Content-Length header if they don't use chunked encoding.
    
    The http::geturl command doesn't provide the Content-Length header if it performs a POST requests with an empty body/query. This is certainly a specific situation, however HTTP post requests with empty body/query are legal requests. However, a missing Content-Length header may create misunderstandings on the server side (e.g. seen with Mongoose 6.4).
    
    The following code lines demonstrate that the Content-Length header is missing for POST requests if the body/query is missing or empty. The code redefines the 'puts' command to print the data transferred through the socket on the standard output.
    
    package require http
    #-> 2.8.9
    
    rename puts puts_orig
    proc puts {args} {
    	::puts_orig stdout "#Std -> [lindex $args end]"
    	::puts_orig {*}$args
    }
    
    http::geturl http://192.168.1.21:8083/JS/Run/zway.controller.data.softwareRevisionVersion.value -method POST
    #Std -> POST /JS/Run/zway.controller.data.softwareRevisionVersion.value HTTP/1.1
    #Std -> Host: 192.168.1.21:8083
    #Std -> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 10.0) http/2.8.9 Tcl/8.6.4
    #Std -> Connection: close
    #Std -> Accept: */*
    #Std -> Accept-Encoding: gzip,deflate,compress
    
    http::geturl http://192.168.1.21:8083/JS/Run/zway.controller.data.softwareRevisionVersion.value -method POST -query ""
    #Std -> POST /JS/Run/zway.controller.data.softwareRevisionVersion.value HTTP/1.1
    #Std -> Host: 192.168.1.21:8083
    #Std -> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 10.0) http/2.8.9 Tcl/8.6.4
    #Std -> Connection: close
    #Std -> Accept: */*
    #Std -> Accept-Encoding: gzip,deflate,compress
    
    http::geturl http://192.168.1.21:8083/JS/Run/zway.controller.data.softwareRevisionVersion.value -method POST -query "Hello"
    #Std -> POST /JS/Run/zway.controller.data.softwareRevisionVersion.value HTTP/1.1
    #Std -> Host: 192.168.1.21:8083
    #Std -> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 10.0) http/2.8.9 Tcl/8.6.4
    #Std -> Connection: close
    #Std -> Accept: */*
    #Std -> Accept-Encoding: gzip,deflate,compress
    #Std -> Content-Type: application/x-www-form-urlencoded
    #Std -> Content-Length: 5
    #Std -> 
    #Std -> Hello
    
    It would be good to fix the http::geturl command in a way that the 'Content-Length' header is also provided for POST requests with empty/missing bodies/queries.
    
  5. foundin changed to: "http package, 2.8.9"
  6. is_private changed to: "0"
  7. login: "droll"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "c7f3b5a0831cb53da82e8d0adc0c229e226e82cc"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "droll"
  14. subsystem changed to: "29. http Package"
  15. title changed to:
    http::geturl : Missing Content-Length header for POST requests
    
  16. type changed to: "Bug"