Package gnu.kawa.servlet
Class HttpRequestContext
java.lang.Object
gnu.kawa.servlet.HttpRequestContext
- Direct Known Subclasses:
KawaHttpHandler.Context,KawaServlet.Context
A representation of an http request as it is being handled.
It abstracts over different http server's API - specially, there are are
concrete implementations on top of JDK6's com.sun.net.httpserver,
javax.servlet.http, and CGI (on top of servlets).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic intThis is a bit of a kludge, to import servlet functions into Scheme.protected static final ThreadLocal<HttpRequestContext> int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ObjectgetAttribute(String name) Get attribute from the server context.abstract StringReturns the context path, relative to the server root.static HttpRequestContextstatic HttpRequestContextgetInstance(String command) Returns the remainder of the request path, relative to the script.abstract intabstract Stringabstract Stringabstract InetAddressabstract Stringabstract intabstract StringgetRequestHeader(String name) getRequestHeaders(String name) abstract StringgetRequestParameter(String name) gnu.kawa.io.InPortabstract InputStreamabstract URIabstract URLgetResourceURL(String path) Returns the URL of a resource.abstract OutputStreamReturn an OutputStream for the result body.Returns the path of the script, relative to the context.static voidhandleStaticFile(HttpRequestContext hctx, gnu.kawa.io.Path absPath) abstract voidabstract voidprotected StringnormalizeToContext(String path) abstract booleanreset(boolean headersAlso) Try to reset (delete) any response generated so far.voidsendNotFound(String path) abstract voidsendResponseHeaders(int reasonCode, String reasonPhrase, long responseLength) Send headers.abstract voidsetAttribute(String name, Object value) Set attribute in the server context.voidsetContentType(String type) static voidabstract voidsetResponseHeader(String name, String value) voidsetScriptAndLocalPath(String scriptPath, String localPath)
-
Field Details
-
HTTP_OK
public static final int HTTP_OK- See Also:
-
HTTP_NOT_FOUND
public static final int HTTP_NOT_FOUND- See Also:
-
statusCode
public int statusCode -
statusReasonPhrase
-
importServletDefinitions
public static int importServletDefinitionsThis is a bit of a kludge, to import servlet functions into Scheme. (The kludge is that we really shouldn't be using a static.) If importServletDefinitions == 1, then we're running in (or compiling for) a web server context; if it is 2 we specifically support servlets. -
instance
-
-
Constructor Details
-
HttpRequestContext
public HttpRequestContext()
-
-
Method Details
-
getInstance
-
getInstance
-
setInstance
-
getRequestStream
-
getRequestPort
public gnu.kawa.io.InPort getRequestPort() -
getRequestBodyChars
- Throws:
IOException
-
getResponseStream
Return an OutputStream for the result body. Multiple calls will return the same OutputStream. -
getConsumer
- Throws:
IOException
-
reset
public abstract boolean reset(boolean headersAlso) Try to reset (delete) any response generated so far.- Parameters:
headersAlso- if response headers should also be reset.- Returns:
- true on success, false if it's too late.
-
getRequestParameter
-
getRequestParameters
-
getRequestURI
-
getContextPath
Returns the context path, relative to the server root. This is an initial substring of thegetRequestPath(). LikeServletContext#getContextPath, but ends with a'/'. The stringgetRequestURI()is the same as the concatenation ofgetContextPath(),getScriptPath(), andgetLocalPath(). -
getScriptPath
Returns the path of the script, relative to the context. LikeServletRequestt#getServletPath, but ends with a'/', and does not start with one. (The reason for this is to produce URIs that work better with operations like resolve-uri.) -
getLocalPath
Returns the remainder of the request path, relative to the script. -
setScriptAndLocalPath
-
getPathTranslated
-
getRequestPath
-
getRequestScheme
-
getLocalSocketAddress
-
getLocalIPAddress
-
getLocalHost
-
getLocalPort
public abstract int getLocalPort() -
getRemoteSocketAddress
-
getRemoteHost
-
getRemoteIPAddress
-
getRemotePort
public abstract int getRemotePort() -
getRequestURLBuffer
-
getQueryString
-
getRequestMethod
-
getRequestHeader
-
getRequestHeaders
-
getRequestHeaders
-
setResponseHeader
-
setContentType
-
normalizeToContext
-
getResourceURL
Returns the URL of a resource. The resource is relative to the script path, if the path is relative; otherwise (if it starts with a'/'it is relative to the context path. -
getAttribute
Get attribute from the server context. -
setAttribute
Set attribute in the server context. -
sendResponseHeaders
public abstract void sendResponseHeaders(int reasonCode, String reasonPhrase, long responseLength) throws IOException Send headers.- Parameters:
reasonCode- response code - e.g. 200 for OK.reasonPhrase- response string - e.g. "OK" or "Not Found".responseLength- response length in bytes, or -1 (unspecified). Note this is different from HttpExchange.sendResponseHeaders. This method must be called before getResponseStream. Implementations should set statusCode to STATUS_SENT.- Throws:
IOException
-
sendNotFound
- Throws:
IOException
-
log
-
log
-
handleStaticFile
public static void handleStaticFile(HttpRequestContext hctx, gnu.kawa.io.Path absPath) throws IOException - Throws:
IOException
-