Check-in [65c26befb0]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improved upload support to not require looking for EOF if content-length is provided
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:65c26befb0f6fda76f45dd801b8292953b16ddb6
User & Date: rkeene 2011-06-14 13:45:16
Context
2011-06-22
22:50
Updated to propogate auto_path to created interpreters check-in: ded8851b04 user: rkeene tags: trunk
2011-06-14
13:45
Improved upload support to not require looking for EOF if content-length is provided check-in: 65c26befb0 user: rkeene tags: trunk
2011-06-12
21:07
Updated to correctly handle requests with no headers check-in: 6d69837cca user: rkeene tags: trunk
Changes

Changes to packages/tclrivet/tclrivet.tcl.

355
356
357
358
359
360
361






362
363
364
365
366
367
368
369
...
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475










476
477
478
479
480
481

482
483


484













485

486



487
488
489
490
491
492
493
					}
					set cache_tmpdir [file join $tmpdir rivet-upload-[pid][expr rand()]]
					catch {
						file mkdir $cache_tmpdir
						file attributes $cache_tmpdir -permissions 0700
					}







					set vals_and_fds_arr [::rivet::handle_upload $inchan $cache_tmpdir $::rivet::cache_vars_contenttype_var(boundary)]
					array set vals [lindex $vals_and_fds_arr 0]
					array set fds [lindex $vals_and_fds_arr 1]

					foreach var [array names vals] {
						if {[info exists fds($var)]} {
							set fd [lindex $fds($var) 0]
							set contenttype [lindex $fds($var) 1]
................................................................................
	if {![info exists retval]} {
		return ""
	}

	return $retval
}

proc ::rivet::handle_upload {fd workdir seperator} {
	array set args {}
	array set argsfd {}

	set seperator "--${seperator}"

	# Select random base name for temporary files
	set basename_tmpfile [file join "$workdir" "upload-[expr rand()][expr rand()][expr rand()]"]

	# Configure fd
	fconfigure $fd -translation binary

	# Process fd into files or arguments










	set nextblock "\015\012[read $fd 1024]"
	set line_oriented 0
	set next_line_oriented 0
	set idx 0
	while 1 {
		if {[string length $nextblock] == 0 && [eof $fd]} {

			break
		}
















		set block $nextblock

		set nextblock [read $fd 1024]



		set bigblock "${block}${nextblock}"

		if {$next_line_oriented} {
			set line_oriented 1

			set next_line_oriented 0
		}







>
>
>
>
>
>
|







 







|












>
>
>
>
>
>
>
>
>
>
|




|
>
|
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>

>
|
>
>
>







355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
...
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
					}
					set cache_tmpdir [file join $tmpdir rivet-upload-[pid][expr rand()]]
					catch {
						file mkdir $cache_tmpdir
						file attributes $cache_tmpdir -permissions 0700
					}

					if {[info exists env(CONTENT_LENGTH)]} {
						set content_length $env(CONTENT_LENGTH)
					} else {
						set content_length -1
					}

					set vals_and_fds_arr [::rivet::handle_upload $inchan $cache_tmpdir $::rivet::cache_vars_contenttype_var(boundary) $content_length]
					array set vals [lindex $vals_and_fds_arr 0]
					array set fds [lindex $vals_and_fds_arr 1]

					foreach var [array names vals] {
						if {[info exists fds($var)]} {
							set fd [lindex $fds($var) 0]
							set contenttype [lindex $fds($var) 1]
................................................................................
	if {![info exists retval]} {
		return ""
	}

	return $retval
}

proc ::rivet::handle_upload {fd workdir seperator content_length} {
	array set args {}
	array set argsfd {}

	set seperator "--${seperator}"

	# Select random base name for temporary files
	set basename_tmpfile [file join "$workdir" "upload-[expr rand()][expr rand()][expr rand()]"]

	# Configure fd
	fconfigure $fd -translation binary

	# Process fd into files or arguments
	if {$content_length == -1 || $content_length > 1024} {
		set bytes_to_read 1024
	} else {
		set bytes_to_read $content_length
	}

	if {$content_length != -1} {
		incr content_length -${bytes_to_read}
	}

	set nextblock "\015\012[read $fd $bytes_to_read]"
	set line_oriented 0
	set next_line_oriented 0
	set idx 0
	while 1 {
		if {[string length $nextblock] == 0} {
			if {$content_length == -1 && [eof $fd]} {
				break
			}
			if {$content_length == 0} {
				break
			}
		}


		if {$content_length == -1 || $content_length > 1024} {
			set bytes_to_read 1024
		} else {
			set bytes_to_read $content_length
		}

		if {$content_length != -1} {
			incr content_length -${bytes_to_read}
		}

		set block $nextblock
		if {$bytes_to_read > 0} {
			set nextblock [read $fd $bytes_to_read]
		} else {
			set nextblock ""
		}
		set bigblock "${block}${nextblock}"

		if {$next_line_oriented} {
			set line_oriented 1

			set next_line_oriented 0
		}