Request Object

Your snakelet gets the current request and response objects in the serve method, and you can do lots of stuff with them:

Scope: request

Method description
getServerSoftware() server software version (string)
getSnakeletsVersion() snakelets version (string)
getServerIP() server IP address (string). Don't use it in an URL, this screws up the virtual hosting feature.
getServerName() published server hostname (string). Taken from the current virtualhost that handles the request. Which can be different from the webapp's owning vhost, because of vhost aliasing. This server name is safe to use in URLs, the virtual hosting will work nicely.
getRealServerName() real (internal) server hostname (string)
getServerProtocol() supported HTTP level (string, "HTTP/1.0")
getServerPort() socket port of the server (int)
getRequestURL() the original full request URL (without hostname and port), for example: "/page/test.cgi?arg=34" Use with the getBaseURL method to obtain a complete URL.
getRequestURLplain() like getRequestURL, but also without any query args. Use with the next method (getBaseURL) to obtain a complete URL without query args.
getBaseURL() the base URL of the server. Example: "http://desertfish.xs4all.nl:9080"
getPathInfo() any additional URL path components after the snakelet URL. Example: when url is 'snoop.sn/foo/bar?arg=value', it returns "/foo/bar". (Note: this is always empty when you use a fnmatch URL pattern for your snakelet!) (this string is not url-escaped)
getMethod() the HTTP method used ("GET" or "POST")
getQuery() the query args of the URL, example: "arg=value&name=foo%21". (this string is still url-escaped)
getFullQueryArgs() all the query args including path info and command, example: "/zip/zap?delete&arg=value&name=foo%21" (note: this is not the full URL! You can get that one from the Snakelet) (this string is still url-escaped)
getRemoteHost() hostname of the remote host (string)
getRemoteAddr() IP address of the remote host (string)
getRealRemoteAddr() the 'real' IP address of the remote host (use this if you are running via Apache Proxy module)
getContentType() the content-type of the request (string)
getContentLength() content length of the request (int)
getUserAgent() browser ID string of the client's browser, or '' (empty string)
getReferer() the referring URL (that is: the url we came from), or '' (empty string)
getCookie() raw cookie information (comma separated string)
getCookies() parsed cookies (mycookie.SimpleRequestCookie object, this is a dict, which maps cookie names to a list of string values)
clearCookies() erases all cookie information from the request (not from the client!)
getInput() request input stream (socket/file)
getArg() URL argument. Example: when url=snoop.sn?command&arg=name it returns "command" (this string is not url-escaped)
setArg(arg) reset the URL argument (getArg() ) to something new.
getWebApp() the current WebApp object
getRangeStr() the unparsed string value of the HTTP 'range' header, or '' (empty string).
getRange() the parsed HTTP 'range' header; a tuple: (from,to)
getAuth() the HTTP Authorization header value, or '' (empty string).
getAllHeaders() all HTTP headers (mimetools.Message object)
getHeader(header) value of specified HTTP header, or None if it isn't present
getForm() parsed form contents (a dict of {param name: value} ) The form has a utility method urlencode() that returns an url-encoded query args string like "arg=value&foo=bar" for the form's parameters.
getField(param, default='') value of a single form field parameter (or the provided default value -which is an empty string if not otherwise given- if the parameter doesn't exist)
getParameter(param, default='') value of a single form field or request context parameter (or the provided default value -which is an empty string if not otherwise given- if the parameter doesn't exist). The request form is first examined, if it does not contain the required field, the request context is examined for a matching attribute. If it too does not have it, the default is returned.
getContext() request context (ContextContainer object). Scope: request. unique per user and per request, destroyed after request completes
getSession() the session object (snakeserver.snakelet.Session object), None if there is no session
deleteSession() logout current user and deletes the session object. Also clears all cookie info on the request (not on the client!)
getSessionContext() the session context (ContextContainer object). Scope: session. unique per user, shared for all requests of this user. None if there is no session.
getMaxPOSTsize() the current max size of a POST request (in bytes)
setMaxPOSTsize(numbytes) set the maximum size in bytes of a POST request (default: 200000=200Kb). If it is larger, the server aborts the connection and the POST request fails, and a FormFileUploadError exception is raised.
getEncoding() the current request character encoding. None if not specified (means default).
setEncoding(encoding) forces the request character encoding. This is often necessary to correctly read non-ASCII characters from From Posts. Also note that returned form fields will be unicode objects (instead of regular strings) if you set the encoding. If you try to change the encoding after the request form fields have already been accessed, a ValueError will be raised. Using this method will override a defaultRequestEncoding that may be defined on the webapp.

Getting request parameters is done using getForm(), or getParameter(). You can clear all parameters for the duration of the reqeuest using getForm().clear() (because it is just a dict). If you need to add or modify request parameters from inside your code, you should update the appropriate keys in the dict object that is returned from getForm().

Snakelets manual - Back to index