how to intercept HTTP GET image/gif

Started by achoo, August 31, 2010, 08:54:30 AM

Previous topic - Next topic

achoo

How can I edit httpd-conf.lsp so that it intercepts requests for image/gif's?



(My plan is to route all google analytics requests for __utm.gif on my test machine to a newLISP instance using the hosts file, and then have the newLISP instance log the requests so I can compare test runs and verify things. If this is a totally misguided concept, feel free to let me know :))

achoo

#1
Here is my httpd-conf.lsp file. When I visit http://my-machine/__utm.gif?asdf=qwer">http://my-machine/__utm.gif?asdf=qwer the only line in the file called "request" is the GET of favicon...


(command-event (fn (s)
(set 'file "request")
(write-file file s)
))

Lutz

#2
two things:



(1) 'command-event' in http-conf.lsp has to return the original or modified request string in order for the httpd web server to work and respond. Right now it returns the return value from 'write-file', which is the number of characters written.



(2) the request for favicon.ico icon is generated by the browser for most page requests you type in. Your program is always overwriting the file "request", so you don't see the requests typed into the web browser.



Modify your http-conf.lsp like this:


(command-event (fn (s)
   (set 'file (string "request" (inc cnt)))
   (write-file file s)
   s
))


Now it will return a valid request string on which the newLISP httpd server can work, and you have request1, request2 ... debug-files for all requests generated by your browser.



ps: here is an even shorter/better version of http-conf.lsp for debugging:
(command-event (fn (s)
   (append-file "requests.txt" s)
   s
))

this is basically generating a log file of all requests.



ps: welcome to newLISP

achoo

#3
Thanks for the help!

achoo

#4
Interesting... Is there a string length limit in newLISP of 254 characters?  Requests that are longer than this get truncated when written to the requests.txt file.



I see this in the documentation:


Quotecommand-event takes either a symbol of a user-defined function or a lambda function. The function for 'command-event' must return a string of 254 characters maximum length.


But this sounds like a limit on what comes out of the function, not a limit on the string while the function is operating on it...

Lutz

#5
This limitation of the output string length of 'command-event' does not exist any more, and the documentation has changed now, to reflect this. But there is still a 254 line length limit for lines in the request header. This is the length of the linefeed terminated lines inside the request header, not the total length of HTTP request. What gets passed into 'command-event' is the first line of that request the line containing the GET, PUT, POST or DELETE keywords.



If 254 is not long enough for a request containing a QUERY_STRING with many variable=value pairs, then a POST request should be issued instead. In practice this limitation has never caused problems. newLISP server mode is mainly designed for usage as a node in a distributed network of newLISP processes talking to each other via HTTP and 'net-eval' requests. Usage of newLISP server as a general purpose HTTP web-server is limited, although limitations are not that many, and it is easy to work around them.