Base class which handles url traversal, response routing and support for standard LLSD services. More...
#include <llhttpnode.h>
Public Member Functions | |
virtual const LLChainIOFactory * | getProtocolHandler () const |
Child Nodes | |
virtual void | addNode (const std::string &path, LLHTTPNode *nodeToAdd) |
LLSD | allNodePaths () const |
Returns an arrary of node paths at and under this node. | |
const LLHTTPNode * | findNode (const std::string &name) const |
const LLHTTPNode * | rootNode () const |
URL traversal | |
The tree is traversed by calling getChild() with successive path components, on successive results. When getChild() returns null, or there are no more components, the last child responds to the request. The default behavior is generally correct, though wildcard nodes will want to implement validate(). | |
virtual LLHTTPNode * | getChild (const std::string &name, LLSD &context) const |
virtual bool | handles (const LLSD &remainder, LLSD &context) const |
const LLHTTPNode * | traverse (const std::string &path, LLSD &context) const |
virtual bool | validate (const std::string &name, LLSD &context) const |
Responses | |
Most subclasses override one or more of these methods to provide the service. By default, the rest of the LLHTTPNode architecture will handle requests, create the needed LLIOPump, parse the input to LLSD, and format the LLSD result to the output. The default implementation of each of these is to call response->methodNotAllowed(); The "simple" versions can be overridden instead in those cases where the service can return an immediately computed response. | |
typedef LLPointer< Response > | ResponsePtr |
virtual void | del (ResponsePtr, const LLSD &context) const |
virtual LLSD | del (const LLSD &context) const |
virtual void | get (ResponsePtr, const LLSD &context) const |
virtual LLSD | get () const |
virtual void | options (ResponsePtr, const LLSD &context) const |
virtual void | post (ResponsePtr, const LLSD &context, const LLSD &input) const |
virtual LLSD | post (const LLSD &input) const |
virtual void | put (ResponsePtr, const LLSD &context, const LLSD &input) const |
virtual LLSD | put (const LLSD &input) const |
Base class which handles url traversal, response routing and support for standard LLSD services.
These classes represent the HTTP framework: The URL tree, and the LLSD REST interface that such nodes implement.
To implement a service, in most cases, subclass LLHTTPNode, implement get() or post(), and create a global instance of LLHTTPRegistration<>. This can all be done in a .cpp file, with no publically declared parts.
To implement a server see lliohttpserver.h
Users of the HTTP responder will typically derive a class from this one, implement the get(), put() and/or post() methods, and then use LLHTTPRegistration to insert it into the URL tree.
The default implementation handles servicing the request and creating the pipe fittings needed to read the headers, manage them, convert to and from LLSD, etc.
LLHTTPNode * LLHTTPNode::getChild | ( | const std::string & | name, | |
LLSD & | context | |||
) | const [virtual] |
returns a child node, if any, at the given name default looks at children and wildcard child (see below)
const LLChainIOFactory * LLHTTPNode::getProtocolHandler | ( | ) | const [virtual] |
Return a factory object for handling wire protocols. The base class returns NULL, as it doesn't know about wire protocols at all. This is okay for most nodes as LLIOHTTPServer is smart enough to use a default wire protocol for HTTP for such nodes. Specialized subclasses that handle things like XML-RPC will want to implement this. (See LLXMLSDRPCServerFactory.)
return true if this node can service the remaining components; default returns true if there are no remaining components
const LLHTTPNode * LLHTTPNode::traverse | ( | const std::string & | path, | |
LLSD & | context | |||
) | const |
find a node, if any, that can service this path set up context["request"] information
bool LLHTTPNode::validate | ( | const std::string & | name, | |
LLSD & | context | |||
) | const [virtual] |
called only on wildcard nodes, to check if they will handle the name; default is false; overrides will want to check name, and return true if the name will construct to a valid url. For convenience, the getChild()
method above will automatically insert the name in context["request"]["wildcard"][key] if this method returns true. For example, the node "agent/<agent_id>/detail" will set context["request"]["wildcard"]["agent_id"] eqaul to the value found during traversal.