Class ::xo::HttpRequest

::xo::HttpRequest[i] create ...

Class Relations

  • class: ::xotcl::Class[i]
  • superclass: ::xo::HttpCore[i]
::xotcl::Class create ::xo::HttpRequest \
     -superclass ::xo::HttpCore

Methods (to be applied on instances)

  • init (scripted)

    # :log "[info exists :timeout]"
    if {[info exists :timeout] && [:timeout] > 0} {
      # create a cond and mutex
      set cond  [thread::cond create]
      set mutex [thread::mutex create]
    
      thread::mutex lock $mutex
    
      # start the asynchronous request
      :debug "--a create new  ::xo::AsyncHttpRequest"
      set req [bgdelivery do -async ::xo::AsyncHttpRequest new  -mixin ::xo::AsyncHttpRequest::RequestManager  -url [:url]  -timeout [:timeout]  -post_data [:post_data]  -request_header_fields [:request_header_fields]  -content_type [:content_type]  -user_agent [:user_agent]  -condition $cond]
    
      while {1} {
        :set_status $cond COND_WAIT_TIMEOUT
        thread::cond wait $cond $mutex [:timeout]
    
        set status [:get_status $cond]
        :debug "status after cond-wait $status"
    
        if {$status ne "COND_WAIT_REFRESH"} break
      }
      if {$status eq "COND_WAIT_TIMEOUT"} {
        :set_status $cond "COND_WAIT_CANCELED"
      }
      set status_value [:get_value_for_status $cond]
      if {$status eq "JOB_COMPLETED"} {
        set :data $status_value
      } else {
        set msg "Timeout-constraint, blocking HTTP request failed. Reason: '$status'"
        if {$status_value ne ""} {
          append msg " ($status_value)"
        }
        error $msg
      }
      thread::cond destroy $cond
      thread::mutex unlock $mutex
      thread::mutex destroy $mutex
      :unset_status $cond
    } else {
      next    ;# HttpCore->init
      #
      # test whether open_connection yielded
      # a socket ...
      #
      # :log "after core init, S?[info exists :S]"
      if {[info exists :S]} {
        :send_request
      }
    }
  • timeout (setter)