Wapp

Ticket Change Details
Login
Overview

Artifact ID: 3ea08819cccd5bac7083d06413c6c250377f16139379eaa7317ede62afc272ef
Ticket: 207094dd9de1343af9d874b8562fc1b4169c3e44
Multiple request in progress can step on each others toes
User & Date: mjanssen 2019-07-30 10:29:17
Changes

  1. Change icomment to:
    diff --git a/modules/wapp-1.0.tm b/modules/wapp-1.0.tm
    index 0467333..57888d1 100644
    --- a/modules/wapp-1.0.tm
    +++ b/modules/wapp-1.0.tm
    @@ -426,7 +426,6 @@ proc wappInt-start-browser {url} {
     # request if $fromip is not an empty string and does not match $ip.
     #
     proc wappInt-new-connection {callback wappmode fromip chan ip port} {
    -  upvar #0 wappInt-$chan W
       if {$fromip!="" && ![string match $fromip $ip]} {
         close $chan
         return
    @@ -434,7 +433,7 @@ proc wappInt-new-connection {callback wappmode fromip chan ip port} {
       set W [dict create REMOTE_ADDR $ip REMOTE_PORT $port WAPP_MODE $wappmode \
              .header {}]
       fconfigure $chan -blocking 0 -translation binary
    -  fileevent $chan readable [list $callback $chan]
    +  fileevent $chan readable [list $callback $W $chan]
     }
     
     # Close an input channel
    @@ -444,21 +443,20 @@ proc wappInt-close-channel {chan} {
         # This happens after completing a CGI request
         exit 0
       } else {
    -    unset ::wappInt-$chan
         close $chan
       }
     }
     
     # Process new text received on an inbound HTTP request
     #
    -proc wappInt-http-readable {chan} {
    -  if {[catch [list wappInt-http-readable-unsafe $chan] msg]} {
    +proc wappInt-http-readable {W chan} {
    +  if {[catch [list wappInt-http-readable-unsafe $W $chan] msg]} {
         puts stderr "$msg\n$::errorInfo"
         wappInt-close-channel $chan
       }
     }
    -proc wappInt-http-readable-unsafe {chan} {
    -  upvar #0 wappInt-$chan W wapp wapp
    +proc wappInt-http-readable-unsafe {W chan} {
    +  upvar #0 wapp wapp
       if {![dict exists $W .toread]} {
         # If the .toread key is not set, that means we are still reading
         # the header
    @@ -481,10 +479,7 @@ proc wappInt-http-readable-unsafe {chan} {
             dict set W SCRIPT_FILENAME $a0
             dict set W DOCUMENT_ROOT [file dir $a0]
           }
    -      if {[wappInt-parse-header $chan]} {
    -        catch {close $chan}
    -        return
    -      }
    +      set W [wappInt-parse-header $W] 
           set len 0
           if {[dict exists $W CONTENT_LENGTH]} {
             set len [dict get $W CONTENT_LENGTH]
    @@ -496,6 +491,7 @@ proc wappInt-http-readable-unsafe {chan} {
             # There is no query content, so handle the request immediately
             set wapp $W
             wappInt-handle-request $chan 0
    +        return
           }
         }
       } else {
    @@ -508,8 +504,10 @@ proc wappInt-http-readable-unsafe {chan} {
           # Handle the request as soon as all the query content is received
           set wapp $W
           wappInt-handle-request $chan 0
    -    }
    +      return
    +    } 
       }
    +  fileevent $chan readable [list wappInt-http-readable $W $chan]
     }
     
     # Decode the HTTP request header.
    @@ -517,8 +515,7 @@ proc wappInt-http-readable-unsafe {chan} {
     # This routine is always running inside of a [catch], so if
     # any problems arise, simply raise an error.
     #
    -proc wappInt-parse-header {chan} {
    -  upvar #0 wappInt-$chan W
    +proc wappInt-parse-header {W} {
       set hdr [split [dict get $W .header] \n]
       if {$hdr==""} {return 1}
       set req [lindex $hdr 0]
    @@ -555,7 +552,7 @@ proc wappInt-parse-header {chan} {
         }
         dict set W $name $value
       }
    -  return 0
    +  return $W
     }
     
     # Decode the QUERY_STRING parameters from a GET request or the
    @@ -618,6 +615,10 @@ proc wappInt-decode-query-params {} {
     #
     proc wappInt-handle-request {chan useCgi} {
       global wapp
    +  if {$chan ni [chan names]} {
    +    return
    +  }
    +  fileevent $chan readable {}
       dict set wapp .reply {}
       dict set wapp .mimetype {text/html; charset=utf-8}
       dict set wapp .reply-code {200 Ok}
    @@ -818,14 +819,13 @@ proc wappInt-handle-cgi-request {} {
     
     # Process new text received on an inbound SCGI request
     #
    -proc wappInt-scgi-readable {chan} {
    -  if {[catch [list wappInt-scgi-readable-unsafe $chan] msg]} {
    +proc wappInt-scgi-readable {W chan} {
    +  if {[catch [list wappInt-scgi-readable-unsafe $W $chan] msg]} {
         puts stderr "$msg\n$::errorInfo"
         wappInt-close-channel $chan
       }
     }
    -proc wappInt-scgi-readable-unsafe {chan} {
    -  upvar #0 wappInt-$chan W wapp wapp
    +proc wappInt-scgi-readable-unsafe {W chan} {
       if {![dict exists $W .toread]} {
         # If the .toread key is not set, that means we are still reading
         # the header.
    @@ -855,6 +855,7 @@ proc wappInt-scgi-readable-unsafe {chan} {
           dict set W SERVER_ADDR [dict get $W .remove_addr]
           set wapp $W
           wappInt-handle-request $chan 0
    +      return
         }
       } else {
         # If .toread is set, that means we are reading the query content.
    @@ -867,8 +868,10 @@ proc wappInt-scgi-readable-unsafe {chan} {
           dict set W SERVER_ADDR [dict get $W .remove_addr]
           set wapp $W
           wappInt-handle-request $chan 0
    +      return
         }
       }
    +  fileevent $chan readable [list wappInt-scgi-readable $W $chan]
     }
     
     # Start up the wapp framework.  Parameters are a list passed as the
    
  2. Change login to "mjanssen"
  3. Change mimetype to "text/plain"
  4. Change priority to "Immediate"
  5. Change resolution to "Open"