[kpax-devel] Recent Changes

Sven Van Caekenberghe scaekenberghe at common-lisp.net
Tue Mar 7 16:32:34 UTC 2006


Today I committed/released the following changes:

Normally, KPAX buffers both its request and response streams, that  
is, get-request-body was always preloaded and cached as a string, and  
output was always written first to get-content-stream, a buffered  
string-output-stream that was only really written out when the  
handling of the request-response was over (when commit was called) -  
this makes it easy to generate correct content-lengths for dynamic  
output (and thus to maintain HTTP keepalive).

This situation remains the default and is the best choice for normal  
dynamic content.

However, when uploading large amounts of data or when serving large  
binary data, this buffering scheme is often not optimal (slower and  
less space efficient). Therefor, the following additions where made:

get-request-body and get-content-stream are now lazy so buffering  
only starts when you are really using it

request and response states are carefully managed using slots in the  
request-response object

get-request-state goes from through the following states (in order):

	NIL
	:request-line-read
	:headers-read
	:body-read

get-response-state goes through the following states (in order):

	NIL
	:response-line-written
	:headers-written
	:response-written
	:response-flushed

All this is invisible to the normal user.

If you did not yet start using the buffered variants, you can now  
access the raw unbuffered streams with

get-request-stream and get-response-stream

calling get-response-stream will automatically call commit-headers,  
but you should really do this manually so that you can pass along the  
content-length, which only you can know up front.

a new example, upload3, uses both of these new features.

the function extract-multipart-parts in multipart-form-encoding.lisp  
was also extended, the new signature is now (stream-or-body-string  
&key use-tmp-files-for-data) meaning that it can parse both a stream  
as well as a string, and that it can store file type parts directly  
in real temporary files and just return the pathname instead of the  
whole content as a string.

please note that these new features do not work for paserve yet.

Serving favicon.ico files was added to s-http-server (just set s-http- 
server:*favicon* to a pathname)

Please let me know if these changes break anything,

Sven


--
Sven Van Caekenberghe - http://homepage.mac.com/svc
Beta Nine - software engineering - http://www.beta9.be

"Lisp isn't a language, it's a building material." - Alan Kay




More information about the kpax-devel mailing list