Class ::xo::AsyncHttpRequest

::xo::AsyncHttpRequest[i] create ...

Class Relations

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

Methods (to be applied on instances)

  • POST (scripted)

    if {[info exists :S]} {fconfigure ${:S} -blocking false}
    fileevent ${:S} writable [list [self] send_POST_data]
    set :bytes_sent 0
    next
  • cancel (scripted)

    if {$reason ne "timeout"} {
      :cancel_timeout
    }
    next
    :notify failure $reason
  • cancel_timeout (scripted)

    if {[info exists :timeout_handle]} {
      after cancel ${:timeout_handle}
    }
  • finish (scripted)

    :cancel_timeout
    next
    :debug "--- finished data ${:data}"
    :notify success ${:data}
  • init (scripted)

    :notify start_request
    :set_timeout
    next
    #
    # test whether open_connection yielded
    # a socket ...
    #
    if {[info exists :S]} {
      fileevent ${:S} writable [list [self] send_request]
    }
  • notify (scripted)

    if {[info exists :request_manager]} {
      [:request_manager] $method $arg [self]
    }
  • receive_reply_data (scripted)

    :instvar S
    :debug "JOB receive_reply_data eof=[eof $S]"
    if {[eof $S]} {
      :finish
    } else {
      :set_timeout
      set block [read $S]
      :notify reply_data $block
      append :data $block
      #:debug "received [string length $block] bytes"
    }
  • reply_first_line_done (scripted)

    :set_timeout
    :instvar S
    fileevent $S readable [list [self] header]
  • reply_header_done (scripted)

    :instvar S
    :set_timeout
    # we have received the header, including potentially the
    # content_type of the returned data
    array set "" [:get_channel_settings [:content_type]]
    fconfigure $S -translation $(translation) -encoding $(encoding)
    fileevent ${:S} readable [list [self] receive_reply_data]
  • request_done (scripted)

    :notify start_reply
    :set_timeout
    :instvar S
    flush $S
    fconfigure $S -blocking false
    fileevent $S readable [list [self] reply_first_line]
  • request_manager (setter)

  • send_POST_data (scripted)

    :instvar S post_data bytes_sent
    :set_timeout
    set total_bytes [string length $post_data]
    if {$bytes_sent < $total_bytes} {
      set to_send [expr {$total_bytes - $bytes_sent}]
      set block_size [expr {$to_send < 4096 ? $to_send : 4096}]
      set next_block_size [expr {$bytes_sent + $block_size}]
      set block [string range $post_data $bytes_sent $next_block_size-1]
      :notify request_data $block
      puts -nonewline $S $block
      set bytes_sent $next_block_size
    } else {
      fileevent $S writable ""
      :request_done
    }
  • send_request (scripted)

    # remove fileevent handler explicitly
    fileevent ${:S} writable {}
    next
  • set_timeout (scripted)

    :cancel_timeout
    :debug "--- setting socket timeout: ${:timeout}"
    set :timeout_handle [after ${:timeout} [self] cancel timeout]
  • timeout (setter)