Qore HttpServerUtil Module Reference 1.1
Loading...
Searching...
No Matches
HttpServerUtil.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* HttpServerUtil.qm Copyright (C) 2014 - 2023 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
25
26
27
144
148namespace HttpServer {
150const HttpServerVersion = "1.1";
151
153const HttpServerString = sprintf("Qore-HTTP-Server/%s", HttpServerVersion);
154
156const DefaultTimeout = 30s; # recvs timeout after 30 seconds
157
160
162
166const MaxSslFileLen = 1024 * 1024;
167
169const HttpCodes = {
170 // 100s: Informational
171 "100": "Continue",
172 "101": "Switching Protocols",
173
174 # RFC 2518: WebDAV
175 "102": "Processing",
176
177 # 200s: Success
178 "200": "OK",
179 "201": "Created",
180 "202": "Accepted",
181 "203": "Non-Authoritative Information",
182 "204": "No Content",
183 "205": "Reset Content",
184 "206": "Partial Content",
185
186 # RFC 4918: WebDAV: The message body that follows is an XML message and can contain a number of separate response
187 # codes, depending on how many sub-requests were made
188 "207": "Multi-Status",
189
190 # RFC 5842: WebDAV: The members of a DAV binding have already been enumerated in a previous reply to this request,
191 # and are not being included again
192 "208": "Already Reported",
193
194 # RFC 3229
195 "226": "IM Used",
196
197 # 300s: Redirection
198 "300": "Multiple Choices",
199 "301": "Moved Permanently",
200 "302": "Found",
201 "303": "See Other",
202 "304": "Not Modified",
203 "305": "Use Proxy",
204 #"306": "(Reserved)",
205 "307": "Temporary Redirect",
206 "308": "Permanent Redirect",
207
208 # 400s: Client Errors
209 "400": "Bad Request",
210 "401": "Unauthorized",
211 "402": "Payment Required",
212 "403": "Forbidden",
213 "404": "Not Found",
214 "405": "Method Not Allowed",
215 "406": "Not Acceptable",
216 "407": "Proxy Authentication Required",
217 "408": "Request Timeout",
218 "409": "Conflict",
219 "410": "Gone",
220 "411": "Length Required",
221 "412": "Precondition Failed",
222 "413": "Request Entity Too Large",
223 "414": "Request-URI Too Long",
224 "415": "Unsupported Media Type",
225 "416": "Requested Range Not Satisfiable",
226 "417": "Expectation Failed",
227
228 # RFC 2324: http://tools.ietf.org/html/rfc2324
229 "418": "I'm a teapot",
230
231 # Returned by the Twitter Search and Trends API when the client is being rate limited
232 "420": "Enhance Your Calm",
233
234 # RFC 4918: WebDAV: The request was well-formed but was unable to be followed due to semantic errors
235 "422": "Unprocessable Entity",
236
237 # RFC 4918: WebDAV: The resource that is being accessed is locked
238 "423": "Locked",
239
240 # RFC 4918: WebDAV: The request failed due to failure of a previous request (e.g. a PROPPATCH)
241 "424": "Failed Dependency",
242
243 # Internet draft: Defined in drafts of "WebDAV Advanced Collections Protocol", but not present in "Web Distributed
244 # Authoring and Versioning (WebDAV) Ordered Collections Protocol"
245 "425": "Unordered Collection",
246
247 # RFC 2817: The client should switch to a different protocol such as TLS/1.0
248 "426": "Upgrade Required",
249
250 # RFC 6585: The origin server requires the request to be conditional. Intended to prevent "the 'lost update'
251 # problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when
252 # meanwhile a third party has modified the state on the server, leading to a conflict."
253 "428": "Precondition Required",
254
255 # RFC 6585: The user has sent too many requests in a given amount of time. Intended for use with rate limiting
256 # schemes
257 "429": "Too Many Requests",
258
259 # RFC 6585
260 "431": "Request Header Fields Too Large",
261
262 # 500s: Server Errors
263 "500": "Internal Server Error",
264 "501": "Not Implemented",
265 "502": "Bad Gateway",
266 "503": "Service Unavailable",
267 "504": "Gateway Timeout",
268 "505": "HTTP Version Not Supported",
269 "509": "Bandwidth Limit Exceeded",
270
271 # RFC 2774: Further extensions to the request are required for the server to fulfill it
272 "510": "Not Extended",
273
274 # RFC 6585: The client needs to authenticate to gain network access. Intended for use by intercepting proxies used
275 # to control access to the network (e.g. "captive portals" used to require agreement to Terms of Service
276 # before granting full Internet access via a Wi-Fi hotspot)
277 "511": "Network Authentication Required",
278};
279
284const LP_LOGPARAMS = 1 << 16;
285
289
291public hashdecl HttpResponseInfo {
293 int code;
294
296
301 *data body;
302
304
309 *InputStream chunked_body;
310
312 softbool close = False;
313
315 *hash<auto> hdr;
316
318 bool reply_sent = False;
319
321 string log;
322
324 string errlog;
325
327 *hash<auto> user_state;
328};
329
331public hashdecl HttpHandlerResponseInfo {
333 int code;
334
336
339 auto body;
340
342 softbool close = False;
343
345
348 *hash<auto> hdr;
349
351 bool reply_sent = False;
352
354 string log;
355
357 string errlog;
358
360 *hash<auto> user_state;
361};
362
363// hashdecl for SSL info
364public hashdecl HttpCertInfo {
366
368 *string cert_loc;
369
371
373 *string key_loc;
374
376
378 *string key_password;
379
381 *SSLCertificate cert;
383 *SSLPrivateKey key;
384};
385
387public hashdecl HttpListenerOptionInfo {
389 *string node;
390
392 *softstring service;
393
395 *string name;
396
398
400 *string cert_loc;
401
403
405 *string key_loc;
406
408
411
414
417
419 *hash<string, hash<HttpHandlerConfigInfo>> handler_info;
420
422 *Logger logger;
423
425 *code stopc;
426
428 int family = AF_UNSPEC;
429
431
434 bool get_remote_certs = False;
435
437
440
442
445
447 hash<auto> ext_info;
448};
449
451public hashdecl HttpHandlerConfigInfo {
453 string path = "/";
454
456 bool isregex = False;
457
459 softlist<softstring> content_types;
460
463
465 softlist<softstring> headers;
466};
467
469
473 string http_get_url_from_bind(softstring bind, *string host);
474
475
477
488 hash<Util::UriQueryInfo> parse_uri_query(string path);
489
490
492 nothing http_set_reply_headers(Socket s, hash<auto> cx, reference<auto> rv, *string server_string);
493
494
496
509 string http_mask_data(string msg);
510
511
513
524 hash<HttpListenerOptionInfo> http_get_listener_options(*string node, *softstring service,
525 *string cert_loc, *string key_loc, *string key_password) {
526 hash<HttpListenerOptionInfo> rv({
527 "node": node,
528 "service": service,
529 });
530 if (cert_loc);
531
532 return rv;
533}
534
536
546 hash<HttpListenerOptionInfo> http_get_listener_options_from_bind(*softstring bind, *string cert_loc,
547 *string key_loc, *string key_password) {
548 hash<HttpListenerOptionInfo> rv();
549 if (cert_loc);
550
551
552 if (bind ==1);
553 else if (bind ==1);
554 else {
555 rv.node = bind;
556 }
557
558 return rv;
559}
560
562
568 hash<HttpListenerOptionInfo> http_get_listener_options_from_bind(*softstring bind,
569 hash<auto> listener_params, hash<HttpListenerOptionInfo> opts = <HttpListenerOptionInfo>{}) {
570 hash<HttpCertInfo> cert_info = http_get_ssl_objects(listener_params);
571 if (cert_info.cert);
572
573
574 if (bind ==1);
575 else if (bind ==1);
576 else {
577 opts.node = bind;
578 }
579
580 return opts;
581}
582
584
594 hash<HttpCertInfo> http_get_ssl_objects(hash<auto> listener_params);
595
596
598
608 hash<HttpCertInfo> http_get_ssl_objects(string cert_loc, *string key_loc, *string pwd);
609
610
613
614public:
616
619 abstract log(string fmt);
620
622
625 abstract logError(string fmt);
626
628
630 logArgs(*softlist<auto> args);
631
632
634
636 logErrorArgs(*softlist<auto> args);
637
638};
639
642
643public:
645
648 abstract addUserThreadContext(hash<auto> uctx);
649
651
654 abstract auto removeUserThreadContext(*string k);
655
657
660 logResponse(hash<auto> cx, hash<auto> rv);
661
662};
663
665
668
669public:
671
675
676
678
680 string getRealm();
681
682
684
692 authenticate(string user, string pass = '');
693
694
696
705 authenticateByIP(string ip, reference<string> user);
706
707
709
711 hash<auto> getAuthHeader();
712
713
715
717 hash<auto> getAuthHeader(hash<auto> cx);
718
719
721
724 hash<HttpResponseInfo> do401(string msg = 'Authentication is required to access this server', *hash<auto> cx);
725
726
728
765 *hash<HttpResponseInfo> authenticateRequest(HttpListenerInterface listener, hash<auto> hdr,
766 reference<hash<auto>> cx) {
767 //printf("HTTP DEBUG %s::authenticateRequest() called\n", self.className());
769 return;
770
771 if (hdr.authorization);
772
773
774 string user;
775 // only try ip-based authentication if the connection is not already authenticated
776 try {
777 authenticateByIP(cx."peer-info".address, \user);
778 cx.user = user;
779 return;
780 } catch (hash<ExceptionInfo> ex) {
781 // log the error
782 string str = sprintf("%s: %s: %s: received from %s", get_ex_pos(ex), ex.err, ex.desc, cx."peer-info".address_desc);
783 listener.logError(str);
784 }
785 return do401(NOTHING, cx);
786 }
787};
788
791
792public:
794
826 *hash<HttpResponseInfo> authenticateRequest(HttpListenerInterface listener, hash<auto> hdr, reference<hash> cx);
827
828};
829
831
848
849public:
850
851
852protected:
858 Socket s;
860 hash<auto> cx;
862 hash<auto> hdr;
864 auto body;
867
868public:
869
871
883 hash<auto> hdr, auto body) {
884 self.listener = listener;
885 self.handler = handler;
886 self.s = s;
887 self.cx = cx;
888 self.hdr = hdr;
889 self.body = body;
890 }
891
893 hash<HttpHandlerResponseInfo> handleRequest();
894
895
897
905protected:
906 hash<HttpHandlerResponseInfo> sendResponse();
907public:
908
909
911
922protected:
923 hash<HttpHandlerResponseInfo> getResponseHeaderMessage();
924public:
925
926
928
930protected:
931 nothing recv(hash<auto> v);
932public:
933
934
936
939protected:
940 auto send();
941public:
942
943
945
954protected:
955 logChunk(bool send, int size);
956public:
957
958
960
975protected:
976 hash<HttpResponseInfo> getResponseHeaderMessageImpl();
977public:
978
979
981
998protected:
999 nothing recvImpl(hash<auto> v);
1000public:
1001
1002
1004
1011protected:
1012 auto sendImpl();
1013public:
1014
1015};
1016
1018
1026
1027public:
1030
1032 bool decompress = True;
1033
1035
1038
1041
1044
1046 const NotificationThreadKey = "_AHRH_pc";
1047
1049 const PersistenceThreadKey = "_AHRH_p";
1050
1052
1057 constructor(*AbstractAuthenticator n_auth, softbool n_stream = False);
1058
1059
1062
1063
1065 setPersistent(bool p = True);
1066
1067
1070
1071
1073
1077 string maskData(string msg);
1078
1079
1082
1085
1088
1089
1091protected:
1092 nothing checkPersistent(hash<auto> cx, hash<auto> hdr);
1093public:
1094
1095
1097
1142 hash<HttpResponseInfo> handleExpectHeader(hash<auto> cx, hash<auto> hdr);
1143
1144
1146
1191 hash<HttpResponseInfo> handleRequest(hash<auto> cx, hash<auto> hdr, *data body);
1192
1193
1195 hash<HttpResponseInfo> handleRequest(HttpListenerInterface listener, Socket s, hash<auto> cx, hash<auto> hdr,
1196 *data body) {
1197 // classic, non-streaming interface
1198 if (!stream);
1199
1200
1201 AbstractStreamRequest req = getStreamRequestImpl(listener, s, cx, hdr, body);
1202 return cast<hash<HttpResponseInfo>>(req.handleRequest());
1203 }
1204
1206 private AbstractStreamRequest getStreamRequestImpl(HttpListenerInterface listener, Socket s, hash<auto> cx,
1207 hash<auto> hdr, *data body) {
1208 return new AbstractStreamRequest(listener, self, s, cx, hdr, body);
1209 }
1210
1212 static data decodeBody(string content_encoding, binary body, *string string_encoding);
1213
1215 static binary encodeBody(string content_encoding, data body);
1216
1218 *data getMessageBody(Socket s, hash<auto> hdr, *data body, bool decode = True);
1219
1220
1222
1255 static *string getLogMessage(hash<auto> cx, hash api, reference params, *reference<string> args);
1256
1258
1262 *hash<auto> saveThreadLocalData();
1263
1264
1266
1268 restoreThreadLocalData(*hash<auto> data);
1269
1270
1272 static hash<HttpResponseInfo> makeResponse(int code, string fmt);
1273
1275 static hash<HttpResponseInfo> makeResponse(hash<auto> hdr, int code, string fmt);
1276
1278 static hash<HttpResponseInfo> makeResponse(int code, binary body);
1279
1281 static hash<HttpResponseInfo> makeResponse(hash<auto> hdr, int code, binary body);
1282
1284 static hash<HttpResponseInfo> makeResponse(int code, *data body, *hash<auto> hdr);
1285
1287
1289 static hash<HttpResponseInfo> makeResponse(int code, *InputStream chunked_body, *hash<auto> hdr);
1290
1292 static hash<HttpResponseInfo> make200(string fmt);
1293
1295 static hash<HttpResponseInfo> make200(hash<auto> hdr, string fmt);
1296
1298 static hash<HttpResponseInfo> make200(hash<auto> hdr, InputStream chunked_body);
1299
1301 static hash<HttpResponseInfo> make200(InputStream chunked_body);
1302
1304 static hash<HttpResponseInfo> make400(string fmt);
1305
1307 static hash<HttpResponseInfo> make400(hash<auto> hdr, string fmt);
1308
1310 static hash<HttpResponseInfo> make500(string fmt);
1311
1313 static hash<HttpResponseInfo> make500(hash<auto> hdr, string fmt);
1314
1316 static hash<HttpResponseInfo> make501(string fmt);
1317
1319 static hash<HttpResponseInfo> make501(hash<auto> hdr, string fmt);
1320
1322 static hash<HttpResponseInfo> redirect(hash<auto> cx, hash<auto> request_hdr, string path, int status_code = 301,
1323 *hash<auto> response_hdr) {
1324 // make sure no forward slashes are doubled in the path
1325 path =~ s/\/+/\//g;
1326 string uri = sprintf("http%s://%s/%s", cx.ssl ? "s" : "", request_hdr.host, path);
1327 return <HttpResponseInfo>{
1328 "code": status_code,
1329 "hdr": response_hdr + {"Location": uri},
1330 "body": request_hdr.method != "HEAD" ? sprintf("redirecting to %s", uri) : NOTHING,
1331 };
1332 }
1333};
1334
1337
1338public:
1340 string url_root;
1341
1343
1348
1349
1351
1354 string getRelativePath(string path);
1355
1356};
1357
1359
1377
1378public:
1379protected:
1381 bool stop = False;
1382
1384 hash<string, int> lh;
1385
1387 hash<string, bool> lsh;
1388
1390 Mutex m();
1391
1392public:
1393
1395
1427 start(softstring lid, hash<auto> cx, hash<auto> hdr, Socket s);
1428
1429
1431
1439 stop(softstring lid);
1440
1441
1443
1449
1450
1452
1471protected:
1472 abstract startImpl(softstring lid, hash<auto> cx, hash<auto> hdr, Socket s);
1473public:
1474
1476
1481protected:
1482 stopImpl(string lid);
1483public:
1484
1485
1487
1489protected:
1491public:
1492
1493};
1494
1496
1499
1500public:
1502
1506
1507};
1508}
abstract base class for external authentication
Definition: HttpServerUtil.qm.dox.h:667
hash< HttpResponseInfo > do401(string msg='Authentication is required to access this server', *hash< auto > cx)
returns a 401 repsonse with the given string argument as the message body
authenticateByIP(string ip, reference< string > user)
called when the connection requires authentication, but no authentication credentials were supplied,...
hash< auto > getAuthHeader()
returns a hash with one item - WWW-Authenticate header set to correct realm
bool requiresAuthentication()
called to check if the connection requires authentication
*hash< HttpResponseInfo > authenticateRequest(HttpListenerInterface listener, hash< auto > hdr, reference< hash< auto > > cx)
primary method called to authenticate each request
Definition: HttpServerUtil.qm.dox.h:765
string getRealm()
returns the authentication realm as a string
hash< auto > getAuthHeader(hash< auto > cx)
returns a hash with one item - WWW-Authenticate header set to correct realm
authenticate(string user, string pass='')
called to authenticate a user for a connection
abstract class that all HTTP request handler objects must inherit from
Definition: HttpServerUtil.qm.dox.h:1025
hash< HttpResponseInfo > handleRequest(HttpListenerInterface listener, Socket s, hash< auto > cx, hash< auto > hdr, *data body)
top-level request handling method
Definition: HttpServerUtil.qm.dox.h:1195
hash< HttpResponseInfo > handleRequest(hash< auto > cx, hash< auto > hdr, *data body)
will be called when a request is received that should be directed to the handler
static hash< HttpResponseInfo > make501(string fmt)
creates a hash for an HTTP 501 error response with the response message body as a string
bool stream
if the handler supports streaming requests/responses with chunked data
Definition: HttpServerUtil.qm.dox.h:1040
notifyClosed(*code c)
calls the argument when the persistent connection is closed
restoreThreadLocalData(*hash< auto > data)
called after handleRequest() with any data returned from saveThreadData()
timeout timeout_ms
send and receive socket timeout in milliseconds
Definition: HttpServerUtil.qm.dox.h:1043
static hash< HttpResponseInfo > makeResponse(int code, string fmt)
creates a hash for an HTTP response with the response code and the response message body as a formatt...
const NotificationThreadKey
thread-local key string for notification callbacks
Definition: HttpServerUtil.qm.dox.h:1046
static hash< HttpResponseInfo > make500(string fmt)
creates a hash for an HTTP 500 error response with the response message body as a string
bool decompress_to_string
if automatically decompressed POSTed data should be converted to a string
Definition: HttpServerUtil.qm.dox.h:1037
private AbstractStreamRequest getStreamRequestImpl(HttpListenerInterface listener, Socket s, hash< auto > cx, hash< auto > hdr, *data body)
returns the AbstractStreamRequest object for handling chunked requests
Definition: HttpServerUtil.qm.dox.h:1206
static data decodeBody(string content_encoding, binary body, *string string_encoding)
decodes a message body with content-encoding
static hash< HttpResponseInfo > makeResponse(int code, *data body, *hash< auto > hdr)
creates a hash for an HTTP response with the response code and a literal response message body
const PersistenceThreadKey
thread-local key string for the persistent flag
Definition: HttpServerUtil.qm.dox.h:1049
static hash< HttpResponseInfo > make200(InputStream chunked_body)
creates a hash for an HTTP 200 OK error response with the response message body from an input stream
*AbstractAuthenticator auth
the optional AbstractAuthenticator for requests to this handler
Definition: HttpServerUtil.qm.dox.h:1029
static hash< HttpResponseInfo > makeResponse(int code, *InputStream chunked_body, *hash< auto > hdr)
creates a hash for an HTTP response with the response code and a response message body from an input ...
bool isPersistent()
returns True if the current connection is persistent, False if not
static staticPersistenceCleanup()
removes the thread-local data key in case the object is destroyed in another thread
static hash< HttpResponseInfo > makeResponse(hash< auto > hdr, int code, binary body)
creates a hash for an HTTP response with the response code and the response message body as binary da...
*data getMessageBody(Socket s, hash< auto > hdr, *data body, bool decode=True)
optionally retrieves and post-processes any message body
static binary encodeBody(string content_encoding, data body)
encodes a message body with content-encoding
nothing persistentClosed()
called externally when a persistent connection is closed
static hash< HttpResponseInfo > make501(hash< auto > hdr, string fmt)
creates a hash for an HTTP 501 error response with the response message body as a string
constructor(*AbstractAuthenticator n_auth, softbool n_stream=False)
create the object optionally with the given AbstractAuthenticator
static hash< HttpResponseInfo > make400(string fmt)
creates a hash for an HTTP 400 error response with the response message body as a string
nothing checkPersistent(hash< auto > cx, hash< auto > hdr)
this method will throw an exception if a persistent connection cannot be granted
bool decompress
if POSTed data should be decompressed automatically if there is content-encoding
Definition: HttpServerUtil.qm.dox.h:1032
static hash< HttpResponseInfo > makeResponse(hash< auto > hdr, int code, string fmt)
creates a hash for an HTTP response with the response code and the response message body as a formatt...
static *string getLogMessage(hash< auto > cx, hash api, reference params, *reference< string > args)
helper method for handling log messages
*hash< auto > saveThreadLocalData()
called before handleRequest()
string maskData(string msg)
this method can be used to mask data in debug messages
static hash< HttpResponseInfo > make500(hash< auto > hdr, string fmt)
creates a hash for an HTTP 500 error response with the response message body as a string
static hash< HttpResponseInfo > make200(hash< auto > hdr, InputStream chunked_body)
creates a hash for an HTTP 200 OK error response with the response message body from an input stream
hash< HttpResponseInfo > handleExpectHeader(hash< auto > cx, hash< auto > hdr)
Called if the request contains an "Expect: 100-continue" header.
static hash< HttpResponseInfo > make200(string fmt)
creates a hash for an HTTP 200 OK error response with the response message body as a string
static staticNotificationCleanup()
removes the thread-local data key in case the object is destroyed in another thread
static hash< HttpResponseInfo > make200(hash< auto > hdr, string fmt)
creates a hash for an HTTP 200 OK error response with the response message body as a string
static hash< HttpResponseInfo > makeResponse(int code, binary body)
creates a hash for an HTTP response with the response code and the response message body as binary da...
static hash< HttpResponseInfo > redirect(hash< auto > cx, hash< auto > request_hdr, string path, int status_code=301, *hash< auto > response_hdr)
generates a redirect hash for the given path
Definition: HttpServerUtil.qm.dox.h:1322
setPersistent(bool p=True)
called externally to notify the handler that the connection will be persistent
static hash< HttpResponseInfo > make400(hash< auto > hdr, string fmt)
creates a hash for an HTTP 400 error response with the response message body as a string
abstract class that all HTTP dedicated socket handler objects must inherit from
Definition: HttpServerUtil.qm.dox.h:1498
constructor(*AbstractAuthenticator auth)
create the object optionally with the given AbstractAuthenticator
Abstract class for HTTP handlers for handling protocol switching.
Definition: HttpServerUtil.qm.dox.h:1376
stop(softstring lid)
called from the HTTP server when the socket should be closed due to an HTTP listener being stopped
stopImpl()
called from the HTTP server when the socket should be closed due to an external request
abstract startImpl(softstring lid, hash< auto > cx, hash< auto > hdr, Socket s)
called from the HTTP server after the handleRequest() method indicates that a dedicated connection sh...
Mutex m()
listener reference hash mutex
hash< string, int > lh
hash of listener references; this is to stop all connections associated with a particular listener
Definition: HttpServerUtil.qm.dox.h:1384
start(softstring lid, hash< auto > cx, hash< auto > hdr, Socket s)
called from the HTTP server after the handleRequest() method indicates that a dedicated connection sh...
hash< string, bool > lsh
hash of listener stop flags
Definition: HttpServerUtil.qm.dox.h:1387
bool stop
stop listener flag
Definition: HttpServerUtil.qm.dox.h:1381
stop()
called from the HTTP server when the socket should be closed due to an external request
stopImpl(string lid)
called from the HTTP server when the socket should be closed because the listener is stopping
this abstract class defines the interface for classes that provide logging methods
Definition: HttpServerUtil.qm.dox.h:612
logArgs(*softlist< auto > args)
calls log() with the given args
logErrorArgs(*softlist< auto > args)
calls logError() with the given args
abstract log(string fmt)
called to log information to the registered log code
abstract logError(string fmt)
called to log error information to the registered error log code
abstract class for streaming HTTP chunked requests/responses
Definition: HttpServerUtil.qm.dox.h:847
auto sendImpl()
callback method for sending chunked data
hash< auto > cx
the call context variable
Definition: HttpServerUtil.qm.dox.h:860
hash< auto > hdr
a hash of request headers
Definition: HttpServerUtil.qm.dox.h:862
constructor(HttpListenerInterface listener, AbstractHttpRequestHandler handler, Socket s, hash< auto > cx, hash< auto > hdr, auto body)
creates the object with the given attributes
Definition: HttpServerUtil.qm.dox.h:882
auto send()
this is the primary callback for sending chunked responses
logChunk(bool send, int size)
this method can be overridden in base classes to log each HTTP chunk sent
AbstractHttpRequestHandler handler
the request handler for the request
Definition: HttpServerUtil.qm.dox.h:856
nothing recvImpl(hash< auto > v)
callback method for receiving chunked data; the default implementation in this base class does nothin...
Socket s
the Socket object for the response
Definition: HttpServerUtil.qm.dox.h:858
hash< HttpHandlerResponseInfo > handleRequest()
handles the request
HttpListenerInterface listener
an HttpListenerInterface object for the listener serving the request for logging purposes
Definition: HttpServerUtil.qm.dox.h:854
timeout timeout_ms
send and receive timeout
Definition: HttpServerUtil.qm.dox.h:866
hash< HttpHandlerResponseInfo > getResponseHeaderMessage()
this method returns the response message description hash by calling getResponseHeaderMessageImpl()
auto body
any message body given in a non-chunked request; could already be deserialized
Definition: HttpServerUtil.qm.dox.h:864
nothing recv(hash< auto > v)
this is the primary callback for receiving chunked data; data will be logged, and then recvImpl() is ...
hash< HttpResponseInfo > getResponseHeaderMessageImpl()
this method should return the response message description hash
hash< HttpHandlerResponseInfo > sendResponse()
called to either create the response hash or send a chunked response directly
abstract class for HTTP request handlers anchored at a specific URL
Definition: HttpServerUtil.qm.dox.h:1336
string url_root
root part of URL for matching requests
Definition: HttpServerUtil.qm.dox.h:1340
constructor(string n_url_root, *AbstractAuthenticator auth)
creates the object based on the URL root and optional authenticator
string getRelativePath(string path)
returns the relative path anchored from the url_root if possible
this abstract class defines the public interface of the private HttpListener class defined in the Htt...
Definition: HttpServerUtil.qm.dox.h:641
abstract addUserThreadContext(hash< auto > uctx)
adds user-defined data to be returned in the "uctx" context key when serving requests from this liste...
abstract auto removeUserThreadContext(*string k)
removes the given key from the "uctx" context key
logResponse(hash< auto > cx, hash< auto > rv)
method to log a response message
class providing automatic authentication for all requests
Definition: HttpServerUtil.qm.dox.h:790
*hash< HttpResponseInfo > authenticateRequest(HttpListenerInterface listener, hash< auto > hdr, reference< hash > cx)
primary method called to authenticate each request
const LP_LEVELMASK
mask for the log level
Definition: HttpServerUtil.qm.dox.h:287
const LP_LOGPARAMS
Definition: HttpServerUtil.qm.dox.h:284
the main namespace for the HttpServer and HttpServerUtil modules
Definition: HttpServerUtil.qm.dox.h:148
const HttpCodes
map of HTTP result codes and text messages
Definition: HttpServerUtil.qm.dox.h:169
const DefaultTimeout
default timeout in ms
Definition: HttpServerUtil.qm.dox.h:156
hash< HttpCertInfo > http_get_ssl_objects(hash< auto > listener_params)
converts a hash to HTTP certificate info if possible
const HttpServerVersion
version of the HttpServer's implementation
Definition: HttpServerUtil.qm.dox.h:150
const ReadTimeout
read timeout in ms
Definition: HttpServerUtil.qm.dox.h:159
nothing http_set_reply_headers(Socket s, hash< auto > cx, reference< auto > rv, *string server_string)
helper function for setting HTTP response headers
string http_get_url_from_bind(softstring bind, *string host)
returns a complete URL from a bind address
hash< HttpListenerOptionInfo > http_get_listener_options(*string node, *softstring service, *string cert_loc, *string key_loc, *string key_password)
returns a listener option info hash from flat arguments
Definition: HttpServerUtil.qm.dox.h:524
const MaxSslFileLen
maximum X.509 and private key file length
Definition: HttpServerUtil.qm.dox.h:166
hash< HttpListenerOptionInfo > http_get_listener_options_from_bind(*softstring bind, *string cert_loc, *string key_loc, *string key_password)
returns a listener option info hash from flat arguments
Definition: HttpServerUtil.qm.dox.h:546
string http_mask_data(string msg)
this function can be used to mask data in log messages
hash< Util::UriQueryInfo > parse_uri_query(string path)
parses a URI path for a arguments and a method
const HttpServerString
default HTTP server string
Definition: HttpServerUtil.qm.dox.h:153
hash providing HTTP handler configuration info
Definition: HttpServerUtil.qm.dox.h:451
string path
the URI path for the handler
Definition: HttpServerUtil.qm.dox.h:453
softlist< softstring > headers
a list of headers that indicate that a request should be handled by the handler (optional)
Definition: HttpServerUtil.qm.dox.h:465
AbstractHttpRequestHandler handler
the handler itself (required)
Definition: HttpServerUtil.qm.dox.h:462
softlist< softstring > content_types
the Content-Type that the handler handles (optional)
Definition: HttpServerUtil.qm.dox.h:459
bool isregex
if the URI path is a regular expression pattern
Definition: HttpServerUtil.qm.dox.h:456
the return value of HTTP handler methods with potentially unserialized message bodies
Definition: HttpServerUtil.qm.dox.h:331
bool reply_sent
this key can be set to True if the reply has already been sent (by a chunked callback for example)
Definition: HttpServerUtil.qm.dox.h:351
*hash< auto > user_state
additional info to be added to the context (cx) variable's user_state key if the connection is not cl...
Definition: HttpServerUtil.qm.dox.h:360
*hash< auto > hdr
set this key to a hash of extra header information to be returned with the response
Definition: HttpServerUtil.qm.dox.h:348
string log
a string can be returned here which will be logged in the HTTP server's log file (if any)
Definition: HttpServerUtil.qm.dox.h:354
string errlog
a string can be returned here which will be logged in the HTTP server's error log file (if any)
Definition: HttpServerUtil.qm.dox.h:357
int code
the HTTP return code (see HttpServer::HttpCodes for possible values)
Definition: HttpServerUtil.qm.dox.h:333
softbool close
set this key to True if the connection should be unconditionally closed when the handler returns
Definition: HttpServerUtil.qm.dox.h:342
auto body
the message body to return in the response
Definition: HttpServerUtil.qm.dox.h:339
options for new listeners
Definition: HttpServerUtil.qm.dox.h:387
*string cert_loc
The X.509 certificate file location.
Definition: HttpServerUtil.qm.dox.h:400
*string node
the node value for the bind
Definition: HttpServerUtil.qm.dox.h:389
int family
network family
Definition: HttpServerUtil.qm.dox.h:428
bool ssl_accept_all_certs
set to False to use openssl CA validation for client certificates
Definition: HttpServerUtil.qm.dox.h:444
*Qore::SSLPrivateKey key
SSL key.
Definition: HttpServerUtil.qm.dox.h:416
*Qore::SSLCertificate cert
SSL cert.
Definition: HttpServerUtil.qm.dox.h:413
hash< auto > ext_info
Additional info added to the notification callback when listeners are started.
Definition: HttpServerUtil.qm.dox.h:447
*Logger logger
logger
Definition: HttpServerUtil.qm.dox.h:422
*hash< string, hash< HttpHandlerConfigInfo > > handler_info
handler info
Definition: HttpServerUtil.qm.dox.h:419
*string key_loc
The private key file location for the X.509 certificate.
Definition: HttpServerUtil.qm.dox.h:405
*string name
the name of the listener
Definition: HttpServerUtil.qm.dox.h:395
bool get_remote_certs
ask for remote client certificates (causes browsers to prompt for a client cert on new connections)
Definition: HttpServerUtil.qm.dox.h:434
*softstring service
the service value for the bind
Definition: HttpServerUtil.qm.dox.h:392
*string key_password
The private key password, if any.
Definition: HttpServerUtil.qm.dox.h:410
*code stopc
stopc stop notification closure
Definition: HttpServerUtil.qm.dox.h:425
int ssl_verify_flags
SSL certificate verification constants; see SSL Verification Mode Constants.
Definition: HttpServerUtil.qm.dox.h:439
the return value of HTTP handler methods where any message body has been serialized for sending over ...
Definition: HttpServerUtil.qm.dox.h:291
softbool close
set this key to True if the connection should be unconditionally closed when the handler returns
Definition: HttpServerUtil.qm.dox.h:312
bool reply_sent
this key can be set to True if the reply has already been sent (by a chunked callback for example)
Definition: HttpServerUtil.qm.dox.h:318
string log
a string can be returned here which will be logged in the HTTP server's log file (if any)
Definition: HttpServerUtil.qm.dox.h:321
*data body
the message body to return in the response
Definition: HttpServerUtil.qm.dox.h:301
int code
the HTTP return code (see HttpServer::HttpCodes for possible values)
Definition: HttpServerUtil.qm.dox.h:293
string errlog
a string can be returned here which will be logged in the HTTP server's error log file (if any)
Definition: HttpServerUtil.qm.dox.h:324
*InputStream chunked_body
the message body to return in the response as a chunked response
Definition: HttpServerUtil.qm.dox.h:309
*hash< auto > user_state
additional info to be added to the context (cx) variable's user_state key if the connection is not cl...
Definition: HttpServerUtil.qm.dox.h:327
*hash< auto > hdr
set this key to a hash of extra header information to be returned with the response
Definition: HttpServerUtil.qm.dox.h:315