Wapp

Diff
Login

Differences From Artifact [de1bd6351e]:

To Artifact [0e8b2953d4]:


371
372
373
374
375
376
377




378
379
380


381
382
383
384
385
386
387
371
372
373
374
375
376
377
378
379
380
381
382


383
384
385
386
387
388
389
390
391







+
+
+
+

-
-
+
+







#
# 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
  set hdr [split [dict get $W .header] \n]
  if {$hdr==""} {
    wappInt-close-channel $chan
    return
  }
  set req [lindex $hdr 0]
  dict set W REQUEST_METHOD [lindex $req 0]
  if {[lsearch {GET HEAD POST} [dict get $W REQUEST_METHOD]]<0} {
  dict set W REQUEST_METHOD [set method [lindex $req 0]]
  if {[lsearch {GET HEAD POST} $method]<0} {
    error "unsupported request method: \"[dict get $W REQUEST_METHOD]\""
  }
  set uri [lindex $req 1]
  set split_uri [split $uri ?]
  set uri0 [lindex $split_uri 0]
  if {![regexp {^/[-.a-z0-9_/]*$} $uri0]} {
    error "invalid request uri: \"$uri0\""
530
531
532
533
534
535
536

537

538
539
540
541
542
543
544
545
546

547




548
549
550
551
552
553
554
534
535
536
537
538
539
540
541

542
543
544
545
546
547
548
549
550
551
552

553
554
555
556
557
558
559
560
561
562
563







+
-
+









+
-
+
+
+
+







    puts $chan "Status: [dict get $wapp .reply-code]\r"
  } else {
    puts $chan "HTTP/1.0 [dict get $wapp .reply-code]\r"
    puts $chan "Server: wapp\r"
    puts $chan "Content-Length: [string length [dict get $wapp .reply]]\r"
    puts $chan "Connection: Closed\r"
  }
  set mimetype [dict get $wapp .mimetype]
  puts $chan "Content-Type: [dict get $wapp .mimetype]\r"
  puts $chan "Content-Type: $mimetype\r"
  if {[dict exists $wapp .new-cookies]} {
    foreach {nm val} [dict get $wapp .new-cookies] {
      if {[regexp {^[a-z][-a-z0-9_]*$} $nm]} {
        set val [wappInt-enc-url $val]
        puts $chan "Set-Cookie: $nm=$val; HttpOnly; Path=/\r"
      }
    }
  }
  puts $chan "\r"
  if {[string match text/* $mimetype]} {
  puts $chan [encoding convertto utf-8 [dict get $wapp .reply]]
    puts $chan [encoding convertto utf-8 [dict get $wapp .reply]]
  } else {
    puts $chan [dict get $wapp .reply]
  }
  flush $chan
  wappInt-close-channel $chan
}

# Process a single CGI request
#
proc wappInt-handle-cgi-request {} {