Wiki source for CommandHttpserver

Show raw source

======Command httpserver======

**httpserver** http server

httpserver [options] [start|stop]

Note: This command is part of the [[CommandsExperimental Experimental Commands]] set and needs to be imported in order to be used.

This command is still under development and is expected to change substantially.

Httpserver starts or stops a single thread which runs an HTTP server within the current shell.
The server is run as a background thread so the command returns immedeately.
Processing of requests is entirely scripted.


||-port port||Listen on the specified port (default 80)||
||-context path||Responds to requests on the given context (default "/")||
||-get cmd||Executes cmd when handling a GET request||
||-put cmd||Executes cmd when handling a PUT request||
||-post cmd|| Executes cmd when handling a POST request||
||-chunk||Operates in HTTP Chunked mode (default is off)||

||start||Starts the HTTP server||
||stop||Stops the HTTP server||


On invocation of a method, $1 is set to the file part of the URI, $2 is set to the query portion of the URI.
The HTTP Request body is made available as stdin to the command, and the output of the command becomes the Response portion.

Like [[EmbeddingServlet xmlsh servlet]] the global variable HTTP_HEADERS is set as with all HTTP headers.


Start a server that serves the file specified by the URL given.
import commands posix
httpserver -port 80 -get 'cat $(xfile . $1)' start

====Return Value====


Valid XHTML :: Valid CSS: :: Powered by WikkaWiki