177 class AbstractTemplate {
196 hash<HttpResponseInfo> render(date new_mtime, hash<auto> ctx,
int http_code = 200, *hash<auto> hdr);
212 abstract hash<HttpResponseInfo> renderImpl(date new_mtime, hash<auto> ctx,
int http_code = 200, *hash<auto> hdr);
221 const DefaultProgramOptions = PO_REQUIRE_OUR|PO_NO_TOP_LEVEL_STATEMENTS|PO_NO_INHERIT_USER_FUNC_VARIANTS|PO_NO_INHERIT_GLOBAL_VARS|PO_NO_USER_CLASSES|PO_NO_TERMINAL_IO;
254 static string getCode(
bool bare_refs,
string fmt);
260 static bool doBlock(
string end, reference<string> src,
string type, reference<int> i, reference<list<hash>> l);
341 hash<HttpResponseInfo>
renderImpl(date new_mtime, hash<auto> ctx,
int http_code = 200, *hash<auto> hdr);
346 setupTemplateIntern(date new_mtime);
363 hash<string, AbstractTemplate>
th;
399 hash<HttpResponseInfo>
render(
string tname,
string path, date mtime, hash<auto> ctx,
int code = 200, *hash<auto> hdr);
418 hash<string, TextTemplateBase>
toh;
421 hash<string, hash<auto>>
th;
461 string add(
string name,
string src, *
string ct);
486 hash<HttpResponseInfo>
render(
string tname, hash<auto> ctx,
int code = 200, *hash<auto> hdr);
505 *hash<HttpResponseInfo>
tryRender(
string tname, hash<auto> ctx,
int code = 200, *hash<auto> hdr);
552 const Unix = (PlatformOS !=
"Windows");
566 "IndexFile":
"index.html",
567 "IndexTemplate":
"index.qhtml",
568 "TemplateExtensions": {
571 "ChunkedThreshold": 10 * 1024,
606 string getDirlistingTemplate();
681 hash<HttpResponseInfo>
fileError(hash<auto> cx, hash<auto> sh);
705 *hash<StatInfo> statPath(hash<auto> cx, hash<auto> hdr, reference<string> path);
784 *hash<HttpResponseInfo>
handleRequestImpl(reference<hash<auto>> cx, hash<auto> hdr, *data body);
AbstractHttpRequestHandler handler
HttpListenerInterface listener
this class serves files from the file system based on a root location
Definition: WebUtil.qm.dox.h:522
softint error_level
set for error info level
Definition: WebUtil.qm.dox.h:549
hash< HttpResponseInfo > fileError(hash< auto > cx, hash< auto > sh)
this method returns a 400 "Bad Request" error code when a file should be served that's not a regular ...
hash< HttpResponseInfo > serverError(hash< auto > cx, hash< auto > ex)
this method returns a 500 "Internal Server Error" error code when an exception occurs
hash< auto > getResponseHeadersForFile(string path, hash< auto > cx, hash< auto > request_hdr)
this method returns a hash giving response headers with a default content type for the file to be ser...
const Defaults
default configuration values
Definition: WebUtil.qm.dox.h:564
softint chunk_size
HTTP chunk size in bytes.
Definition: WebUtil.qm.dox.h:541
logError(string fmt)
default implementation is empty; this method is called with error log messages; reimplement in subcla...
const DefaultFileReadTimeout
default read timeout for serving files
Definition: WebUtil.qm.dox.h:555
const Dirlisting
dirlisting template
Definition: WebUtil.qm.dox.h:576
StaticTemplateManager stm()
static templates
AbstractStreamRequest getStreamRequestImpl(HttpServer::HttpListenerInterface listener, Qore::Socket s, hash< auto > cx, hash< auto > hdr, *data body, InputStream stream, *hash< auto > respHdr)
must return a AbstractStreamRequest object to stream the requested file with chunked transfer encodin...
*hash< HttpResponseInfo > renderDirectory(hash< auto > cx, string path)
this method is called when a directory should be rendered
logDebug(string fmt)
default implementation is empty; this method is called with debug log messages; reimplement in subcla...
const Unix
flag for UNIX operating systems
Definition: WebUtil.qm.dox.h:552
*hash< HttpResponseInfo > tryServeRequest(HttpServer::HttpListenerInterface listener, Qore::Socket s, hash< auto > cx, hash< auto > hdr, *data body)
tries to serve the request from the filesystem
*string default_target
the default target if a URL cannot be satisfied
Definition: WebUtil.qm.dox.h:535
hash< HttpResponseInfo > sendFile(InputStream stream, *hash< auto > respHdr)
returns a handler hash response with the data to be sent in a monolithic message
hash< HttpResponseInfo > handleRequest(HttpServer::HttpListenerInterface listener, Qore::Socket s, hash< auto > cx, hash< auto > hdr, *data body)
this method calls handleRequestImpl() to service the request, if handleRequestImpl() returns NOTHING,...
const DirSep
directory separator character
Definition: WebUtil.qm.dox.h:561
hash< HttpResponseInfo > unhandledRequest(hash< auto > cx, hash< auto > hdr, *data body)
this method returns a 404 "Not Found" error code to GET requests and a 501 "Not Implemented" error co...
softlist indexes
indexes for directories; handled in order of appearance
Definition: WebUtil.qm.dox.h:529
string file_root
root directory for serving files
Definition: WebUtil.qm.dox.h:526
softint chunked_threshold
minimum size in bytes for plain files to be sent with a chnked transfer
Definition: WebUtil.qm.dox.h:538
logInfo(string fmt)
default implementation is empty; this method is called with informational log messages; reimplement i...
hash template_extensions
file extensions handled as templates
Definition: WebUtil.qm.dox.h:532
hash< HttpResponseInfo > sendFileChunked(HttpServer::HttpListenerInterface listener, Qore::Socket s, hash< auto > cx, hash< auto > hdr, *data body, InputStream stream, *hash< auto > respHdr)
returns a handler hash response with the file's data to be sent in a HTTP message with chunked transf...
constructor(string new_file_root, string url_root='/', *hash< auto > opt)
create the object optionally with the given HttpServer::AbstractAuthenticator
*hash< HttpResponseInfo > handleRequestImpl(reference< hash< auto > > cx, hash< auto > hdr, *data body)
this method is called by this class's handleRequest() before trying to service the request automatica...
this class handles chunked file sends
Definition: WebUtil.qm.dox.h:108
hash< HttpResponseInfo > getResponseHeaderMessageImpl()
returns the reponse headers
bool txt
text flag
Definition: WebUtil.qm.dox.h:117
constructor(HttpServer::HttpListenerInterface listener, HttpServer::AbstractHttpRequestHandler handler, Qore::Socket s, hash< auto > cx, hash< auto > hdr, *data body, Qore::ReadOnlyFile file, bool textflag, int chunk_size, *hash< auto > respHdr)
creates the object
auto sendImpl()
returns data to send
int cs
chunk size
Definition: WebUtil.qm.dox.h:119
*hash< auto > respHdr
response headers
Definition: WebUtil.qm.dox.h:121
ReadOnlyFile f
file object
Definition: WebUtil.qm.dox.h:115
manages a template resource that may need to be recompiled if the file is updated in the filesystem; ...
Definition: WebUtil.qm.dox.h:288
int po
parse options used on the program
Definition: WebUtil.qm.dox.h:293
string ct
the content type of the rendered template
Definition: WebUtil.qm.dox.h:299
RWLock rwl()
to ensure atomicity regarding contention between setup/recompiles and rendering requests
*code psetup
code to perform Program initialization when creating a new Program object (inport API,...
Definition: WebUtil.qm.dox.h:305
const TemplateFunc
the name of the template function
Definition: WebUtil.qm.dox.h:302
string path
the path to the template
Definition: WebUtil.qm.dox.h:296
*date mtime
file's modification time
Definition: WebUtil.qm.dox.h:311
constructor(string resource_path, int parse_opts=DefaultProgramOptions, *code pgm_setup)
creates the object based on the pathname and Program options
hash< HttpResponseInfo > renderImpl(date new_mtime, hash< auto > ctx, int http_code=200, *hash< auto > hdr)
explicitly renders the given template with the given argument
A container for holding static text templates (ie that do not change once created in the template man...
Definition: WebUtil.qm.dox.h:413
Sequence seq()
Sequence for template function names.
int po
parse options for template containers
Definition: WebUtil.qm.dox.h:427
constructor(int po=DefaultProgramOptions)
sets up the object
hash< string, hash< auto > > th
Maps template names to function names.
Definition: WebUtil.qm.dox.h:421
*hash< string, bool > getTemplateHash()
returns a hash of template names, values are True or NOTHING if no templates are currently cached
setupProgram(Program p)
override in subclasses to customize the setup of template Programs; this method performs no action
string add(string name, string src, *string ct)
adds a template to the object
list< string > getTemplateList()
returns a list of template names, an empty list is returned if there are no templates
bool hasTemplate(string tname)
returns True if the given template exists, False if not
hash< string, TextTemplateBase > toh
Maps template names to TextTemplateBase objects.
Definition: WebUtil.qm.dox.h:418
*hash< HttpResponseInfo > tryRender(string tname, hash< auto > ctx, int code=200, *hash< auto > hdr)
explicitly renders the given template with the given argument context hash if the template exists; if...
hash< HttpResponseInfo > render(string tname, hash< auto > ctx, int code=200, *hash< auto > hdr)
explicitly renders the given template with the given argument
this is the static base class for all template Program container classes
Definition: WebUtil.qm.dox.h:217
const DefaultProgramOptions
default parse options for template Programs
Definition: WebUtil.qm.dox.h:221
static string getContentType(string name)
returns the content type from the file name, ignores any leading "q" in the extensions,...
static string add(Qore::Program p, string fn, string name, string src)
adds a template function to a template Program object
static bool doBlock(string end, reference< string > src, string type, reference< int > i, reference< list< hash > > l)
a helper method used in parsing
static string getCode(bool bare_refs, string fmt)
a helper method that strips dollar signs from code when PO_ALLOW_BARE_REFS is set in the template pro...
this class manages templates based on files
Definition: WebUtil.qm.dox.h:355
hash< string, AbstractTemplate > th
hash for template storage
Definition: WebUtil.qm.dox.h:363
purge(string tname)
this method can be called when a resource is requested that no longer exists in case a template is st...
hash< HttpResponseInfo > render(string tname, string path, date mtime, hash< auto > ctx, int code=200, *hash< auto > hdr)
explicitly renders the given template with the given path and context argument
RWLock rwl()
read-write lock for managing template access
*code psetup
code to perform Program initialization when creating a new Program object (inport API,...
Definition: WebUtil.qm.dox.h:369
int po
parse options used on the program
Definition: WebUtil.qm.dox.h:366
constructor(int parse_opts=StaticTextTemplateBase::DefaultProgramOptions, *code pgm_setup)
creates the object with optional Program options
this is the base class for all template Program container classes
Definition: WebUtil.qm.dox.h:269
Program p
Holds the template generation function.
Definition: WebUtil.qm.dox.h:274
Program getProgram()
returns the contained Program object
constructor(int po=DefaultProgramOptions)
sets up the object
the WebUtil namespace contains all the objects in the WebUtil module
Definition: WebUtil.qm.dox.h:106