So it's nearly midnight here and I'm working on a http server idea. I'm using HttpServerServlets which is part of my streaming HTTP/1.1 server and every time I want a new 'servlet' I have to make a subclass of the class Servlet.
 This is pretty much bespoke as to the way servlets were designed for Java. This is also pretty much the way VW and VA offer you the ability to do servlets. Subclass the servlet class and implement a do*Method: method and you're away. Pretty neat, but... often each class has one method in it to return some sort of dynamically generated page.
So I got thinking about pragmas again - or as Travis wants to call them: "tags". I thought, what if I could just make one class and put all these adhoc response methods in there using tags. So I've come up with a couple of tags you can put in to a subclass of HttpServerTags.TagServer.
 static_content
	
	
	^'Hello World'
 
 In this simple example we say that we respond to a GET request with path of /test.txt and our content type is text/plain. When we request the page, we get back a string of Hello World. Pretty simple and to the point. Let's get a bit more interesting:
 streaming_content: request stream: stream
	
	
	
	600 timesRepeat: [
		(Delay forMilliseconds: 6) wait.
		stream asStringStream nextPutAll: Timestamp now printString; cr.
		stream flush]
 
 In this example, we respond to /streaming.txt and it will disable any compression so that we can see a streaming response in our web browser immediately. It will send us the next timestamp for the next 10 seconds.
 Pretty neat isn't it - we get past a lot of the boring setup we'd normally have to do to make a response such as setting up contentType: on the response object ourselves. Let's get more interesting.
 session_info: request writer: writer
	
	
	
	writer html: [:html | html body div text: request session printString].
 
 In this example, we say we're outputting html - this takes care of the content type for us, but more interestingly, it also sets us up with my new XMLWriter object that lets us quickly dump out some xml without having to write it all ourselves. The XMLWriter itself is a stream, so you cannot go back and add attributes to a tag you've already added children to or add more children to a prior sibling etc.
 Instead of using  we can just as easily also use  which does the same thing, except it sets the content-type to be text/xml.
 So in the example above, we get our session set up for us as well, simply by putting the session pragma in there.
 One more example - replying with files. Because of the way we do the matching on get:, post:, put:, delete: pragmas, they actually match as a prefix to the uri path, so we can do the following:
 scripts: request
	
	self respondFromDisk: request
 
 This picks up the disk response behaviour which does last-modifies, 404 not founds, etc for you as well. I'm pretty pleased with the way this Servlet replacement turned out. Give it a go and let me know what you think too. The package that enables this is called HttpServerTags and is now available in Public Store.