102 constructor(
HttpServer::HttpListenerInterface listener,
HttpServer::AbstractHttpRequestHandler handler,
Qore::Socket s,
hash cx,
hash hdr, *data
body,
Qore::ReadOnlyFile file,
bool textflag,
string content_type,
int chunk_size, *
hash respHdr) ;
172 static string getCode(
bool bare_refs,
string fmt);
179 static bool doBlock(
string end, reference<string> src,
string type, reference<int> i, reference<list<hash>> l);
248 setupTemplateIntern(
date new_mtime);
357 string add(
string name,
string src, *
string ct);
456 "IndexFile":
"index.html",
457 "IndexTemplate":
"index.qhtml",
458 "TemplateExtensions": (
461 "ChunkedThreshold": 10 * 1024,
469 " $d.chdir($ctx.path);"
470 " string $title = sprintf(\"Index of /%s\", $ctx.resource_path);"
473 " <meta charset=\"utf-8\" />"
474 " <title>{{ $title }}</title>"
478 " <h1>{{ $title }}</h1>"
480 " <div class=\"container\">"
484 " <th width=\"40\">Type</th>"
485 " <th width=\"80\">Size</th>"
487 " {% if ($ctx.parent_url) { %}"
489 " <td colspan=\"2\"><a href=\"{{ $ctx.parent_url }}\">Parent Directory</a></td>"
492 " {% foreach string $dir in (sort($d.listDirs())) { %}"
493 " {% if ($dir[0]!=\".\") {"
494 " string $path = replace($ctx.path, $ctx.file_root, \"\");"
496 " <tr><td><a href=\"{{ $ctx.url_root + $path + \"/\" + $dir }}\">{{ $dir }}</a></td><td width=\"40\">Directory</td></tr>"
499 " {% foreach string $file in (sort($d.listFiles())) { %}"
500 " {% if ($file[0]!=\".\") {"
501 " string $path = replace($ctx.path, $ctx.file_root, \"\");"
503 " <tr><td><a href=\"{{ $ctx.url_root + $path + \"/\" + $file }}\">{{ $file }}</a></td><td width=\"40\">File</td><td align=\"right\">{{hstat($ctx.path + \"/\" + $file).size }}</td></tr>"
536 string getDirlistingTemplate();
const Dirlisting
dirlisting template
Definition: WebUtil.qm.dox.h:466
logInfo(string fmt)
default implementation is empty; this method is called with informational log messages; reimplement i...
bool hasTemplate(string tname)
returns True if the given template exists, False if not
softint error_level
set for error info level
Definition: WebUtil.qm.dox.h:442
*date mtime
file's modification time
Definition: WebUtil.qm.dox.h:211
manages a template resource that may need to be recompiled if the file is updated in the filesystem; ...
Definition: WebUtil.qm.dox.h:188
hash th
hash for template storage
Definition: WebUtil.qm.dox.h:265
constructor(int parse_opts=TextTemplateBase::DefaultProgramOptions, *code pgm_setup)
creates the object with optional Program options
hash serverError(hash cx, hash ex)
this method returns a 500 "Internal Server Error" error code when an exception occurs ...
*code psetup
code to perform Program initialization when creating a new Program object (inport API...
Definition: WebUtil.qm.dox.h:205
string ct
Content-Type.
Definition: WebUtil.qm.dox.h:93
string ct
the content type of the rendered template
Definition: WebUtil.qm.dox.h:199
string add(string name, string src, *string ct)
adds a template to the object
int po
parse options used on the program
Definition: WebUtil.qm.dox.h:193
hash getResponseHeaderMessageImpl()
returns the reponse headers
ReadOnlyFile f
file object
Definition: WebUtil.qm.dox.h:89
hash sendFileChunked(HttpServer::HttpListenerInterface listener, Qore::Socket s, hash cx, hash hdr, *data body, Qore::ReadOnlyFile f, bool txt, string ct, *hash respHdr)
returns a handler hash response with the file's data to be sent in a HTTP message with chunked transf...
*hash tryServeRequest(HttpServer::HttpListenerInterface listener, Qore::Socket s, hash cx, hash hdr, *data body)
tries to serve the request from the filesystem
this is the base class for all template Program container classes
Definition: WebUtil.qm.dox.h:121
constructor(HttpServer::HttpListenerInterface listener, HttpServer::AbstractHttpRequestHandler handler, Qore::Socket s, hash cx, hash hdr, *data body, Qore::ReadOnlyFile file, bool textflag, string content_type, int chunk_size, *hash respHdr)
creates the object
this class manages templates based on files
Definition: WebUtil.qm.dox.h:257
softint chunk_size
HTTP chunk size in bytes.
Definition: WebUtil.qm.dox.h:434
*hash tryRender(string tname, hash ctx, int code=200, *hash hdr)
explicitly renders the given template with the given argument context hash if the template exists; if...
AbstractHttpRequestHandler handler
static string getContentType(string name)
returns the content type from the file name, ignores any leading "q" in the extensions, assuming a template
const TemplateFunc
the name of the template function
Definition: WebUtil.qm.dox.h:202
hash fileError(hash cx, hash sh)
this method returns a 400 "Bad Request" error code when a file should be served that's not a regula...
const Defaults
default configuration values
Definition: WebUtil.qm.dox.h:454
*hash respHdr
response headers
Definition: WebUtil.qm.dox.h:97
*string default_target
the default target if a URL cannot be satisfied
Definition: WebUtil.qm.dox.h:428
const PO_NO_INHERIT_GLOBAL_VARS
constructor(int po=DefaultProgramOptions)
sets up the object
*hash handleRequestImpl(reference< hash > cx, hash hdr, *data body)
this method is called by this class's handleRequest() before trying to service the request automatica...
bool txt
text flag
Definition: WebUtil.qm.dox.h:91
hash render(string tname, string path, date mtime, hash ctx, int code=200, *hash hdr)
explicitly renders the given template with the given path and context argument
RWLock rwl()
to ensure atomicity regarding contention between setup/recompiles and rendering requests ...
constructor(string new_file_root, string url_root="/", *hash opt)
create the object optionally with the given HttpServer::AbstractAuthenticator
this class serves files from the file system based on a root location
Definition: WebUtil.qm.dox.h:414
*code psetup
code to perform Program initialization when creating a new Program object (inport API...
Definition: WebUtil.qm.dox.h:271
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...
hash render(date new_mtime, hash ctx, int code=200, *hash hdr)
explicitly renders the given template with the given argument
hash template_extensions
file extensions handled as templates
Definition: WebUtil.qm.dox.h:425
int po
parse options used on the program
Definition: WebUtil.qm.dox.h:268
softint chunked_threshold
minimum size in bytes for plain files to be sent with a chnked transfer
Definition: WebUtil.qm.dox.h:431
list getTemplateList()
returns a list of template names, an empty list is returned if there are no templates ...
softlist indexes
indexes for directories; handled in order of appearance
Definition: WebUtil.qm.dox.h:422
constructor(string resource_path, int parse_opts=DefaultProgramOptions, *code pgm_setup)
creates the object based on the pathname and Program options
FileStreamRequest getFileStreamRequestImpl(HttpServer::HttpListenerInterface listener, Qore::Socket s, hash cx, hash hdr, *data body, Qore::ReadOnlyFile f, bool txt, string ct, *hash respHdr)
must return a FileStreamRequest object to stream the requested file with chunked transfer encoding ...
A container for holding static text templates (ie that do not change once created in the template man...
Definition: WebUtil.qm.dox.h:315
constructor(int po=DefaultProgramOptions)
sets up the object
auto sendImpl()
returns data to send
HttpListenerInterface listener
const PO_NO_INHERIT_USER_FUNC_VARIANTS
*hash getTemplateHash()
returns a hash of template names, values are True or NOTHING if no templates are currently cached ...
logError(string fmt)
default implementation is empty; this method is called with error log messages; reimplement in subcla...
*hash renderDirectory(hash cx, string path)
this method is called when a directory should be rendered
hash unhandledRequest(hash cx, hash hdr, *data body)
this method returns a 404 "Not Found" error code to GET requests and a 501 "Not Implemented" error co...
string path
the path to the template
Definition: WebUtil.qm.dox.h:196
*hash getResponseHeadersForFile(string path, hash cx, hash hdr)
this method returns NOTHING by default but can be subclassed to add headers to the response ...
purge(string tname)
this method can be called when a resource is requested that no longer exists in case a template is st...
Sequence seq()
Sequence for template function names.
StaticTemplateManager stm()
static templates
const DirSep
directory separator character
Definition: WebUtil.qm.dox.h:451
this class handles chunked file sends
Definition: WebUtil.qm.dox.h:80
string file_root
root directory for serving files
Definition: WebUtil.qm.dox.h:419
const Unix
flag for UNIX operating systems
Definition: WebUtil.qm.dox.h:445
Program p
Holds the template generation function.
Definition: WebUtil.qm.dox.h:126
const DefaultProgramOptions
default parse options for template Programs
Definition: WebUtil.qm.dox.h:132
hash sendFile(ReadOnlyFile f, bool txt, string ct, *hash respHdr)
returns a handler hash response with the file's data to be sent in a monolithic message ...
const PO_NO_TOP_LEVEL_STATEMENTS
hash render(string tname, hash ctx, int code=200, *hash hdr)
explicitly renders the given template with the given argument
logDebug(string fmt)
default implementation is empty; this method is called with debug log messages; reimplement in subcla...
hash th
Maps template names to function names.
Definition: WebUtil.qm.dox.h:320
RWLock rwl()
read-write lock for managing template access
static bool doBlock(string end, reference< string > src, string type, reference< int > i, reference< list< hash >> l)
a helper method used in parsing
hash handleRequest(HttpServer::HttpListenerInterface listener, Qore::Socket s, hash cx, hash hdr, *data body)
this method calls handleRequestImpl() to service the request, if handleRequestImpl() returns NOTHING...
static string add(Qore::Program p, string fn, string name, string src)
adds a template function to a template Program object
int cs
chunk size
Definition: WebUtil.qm.dox.h:95