Re: [spr28609] Allegroserve doesn't seems to provide USER AGENT information

John Foderaro <[email protected]> Mon, 23 Feb 2004 09:17:38 -0800
Newsgroups gmane.lisp.open-source.franz
Message-ID <[email protected]>
>> Karsten wrote...
>>
>> I use (net.aserve::request-header-user-agent request)
>> and it seems to work fine.
>> (net.aserve:header-slot-value request :user-agent) does not seem to work


This is not what I'd expect to happen.  Perhaps you could show
me an example where you see this behavior.

Here's an example of what I think should happen.
I've taken one of the examples in the examples.cl distributed
with AllegroServe and added some print statements to test
the two different ways of accessing the user-agent header value.


First it tries accessing the internal slot of the request object
    (net.aserve::request-header-user-agent request)

then it tries the documented way of accessing this header value:
    (net.aserve:header-slot-value request :user-agent)

and then it repeats the two accesses.

What you find is that 
    (net.aserve:header-slot-value request :user-agent)
always returns the correct value.

Also you find  that the internal slot 
    (net.aserve::request-header-user-agent request)
returns nil the first time and the correct value the second time.
This is because this slot is used to cache the return value 
from the call to 
    (net.aserve:header-slot-value request :user-agent)
so it only will give the correct value after
    (net.aserve:header-slot-value request :user-agent)
is called.


here's the modified example form examples.cl


(publish :path "/hello"
	 :content-type  "text/html"
	 :function 
	 #'(lambda (req ent)
	     (with-http-response (req ent)
	       (with-http-body (req ent)
		 (dotimes (i 2)
		   (format t "~%Try number ~s~%" (1+ i))
		   (format 
		    t "(net.aserve::request-header-user-agent req) => ~s~%"
		    (net.aserve::request-header-user-agent req))
				   
		   (format t "(header-slot-value req :user-agent) => ~s~%"
			   (header-slot-value req :user-agent))
		 
		   (format t "---------~%"))
				   
		 (html "Hello World!")))))


and here's the result running it:


Try number 1
(net.aserve::request-header-user-agent req) => nil
(header-slot-value req :user-agent) => "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031007"
---------

Try number 2
(net.aserve::request-header-user-agent req) => "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031007"
(header-slot-value req :user-agent) => "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031007"
---------
192.132.95.103 - - [Mon, 23 Feb 2004 17:11:03 GMT] "GET /hello HTTP/1.1" 200 12