Logo ROOT   6.12/07
Reference Guide
TCivetweb.cxx
Go to the documentation of this file.
1 // $Id$
2 // Author: Sergey Linev 21/12/2013
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TCivetweb.h"
13 
14 #include "../civetweb/civetweb.h"
15 
16 #include <stdlib.h>
17 #include <string.h>
18 
19 #include "THttpServer.h"
20 #include "THttpWSEngine.h"
21 #include "TUrl.h"
22 
23 //////////////////////////////////////////////////////////////////////////
24 // //
25 // TCivetwebWSEngine //
26 // //
27 // Implementation of THttpWSEngine for Civetweb //
28 // //
29 //////////////////////////////////////////////////////////////////////////
30 
31 class TCivetwebWSEngine : public THttpWSEngine {
32 protected:
33  struct mg_connection *fWSconn;
34 
35 public:
36  TCivetwebWSEngine(const char *name, const char *title, struct mg_connection *conn)
37  : THttpWSEngine(name, title), fWSconn(conn)
38  {
39  }
40 
41  virtual ~TCivetwebWSEngine() {}
42 
43  virtual UInt_t GetId() const { return TString::Hash((void *)fWSconn, sizeof(void *)); }
44 
45  virtual void ClearHandle() { fWSconn = 0; }
46 
47  virtual void Send(const void *buf, int len)
48  {
49  if (fWSconn)
50  mg_websocket_write(fWSconn, WEBSOCKET_OPCODE_TEXT, (const char *)buf, len);
51  }
52 };
53 
54 //////////////////////////////////////////////////////////////////////////
55 
56 int websocket_connect_handler(const struct mg_connection *conn, void *)
57 {
58  const struct mg_request_info *request_info = mg_get_request_info(conn);
59  if (request_info == 0)
60  return 1;
61 
62  TCivetweb *engine = (TCivetweb *)request_info->user_data;
63  if (engine == 0)
64  return 1;
65  THttpServer *serv = engine->GetServer();
66  if (serv == 0)
67  return 1;
68 
69  THttpCallArg arg;
70  arg.SetPathAndFileName(request_info->uri); // path and file name
71  arg.SetQuery(request_info->query_string); // query arguments
72  arg.SetWSId(TString::Hash((void *)conn, sizeof(void *)));
73  arg.SetMethod("WS_CONNECT");
74 
75  Bool_t execres = serv->ExecuteHttp(&arg);
76 
77  return execres && !arg.Is404() ? 0 : 1;
78 }
79 
80 //////////////////////////////////////////////////////////////////////////
81 
82 void websocket_ready_handler(struct mg_connection *conn, void *)
83 {
84  const struct mg_request_info *request_info = mg_get_request_info(conn);
85 
86  TCivetweb *engine = (TCivetweb *)request_info->user_data;
87  if (engine == 0)
88  return;
89  THttpServer *serv = engine->GetServer();
90  if (serv == 0)
91  return;
92 
93  THttpCallArg arg;
94  arg.SetPathAndFileName(request_info->uri); // path and file name
95  arg.SetQuery(request_info->query_string); // query arguments
96  arg.SetMethod("WS_READY");
97 
98  arg.SetWSId(TString::Hash((void *)conn, sizeof(void *)));
99  arg.SetWSHandle(new TCivetwebWSEngine("websocket", "title", conn));
100 
101  serv->ExecuteHttp(&arg);
102 }
103 
104 //////////////////////////////////////////////////////////////////////////
105 
106 int websocket_data_handler(struct mg_connection *conn, int, char *data, size_t len, void *)
107 {
108  const struct mg_request_info *request_info = mg_get_request_info(conn);
109 
110  // do not handle empty data
111  if (len == 0)
112  return 1;
113 
114  TCivetweb *engine = (TCivetweb *)request_info->user_data;
115  if (engine == 0)
116  return 1;
117  THttpServer *serv = engine->GetServer();
118  if (serv == 0)
119  return 1;
120 
121  // seems to be, appears when connection is broken
122  if ((len == 2) && ((int)data[0] == 3) && ((int)data[1] == -23))
123  return 0;
124 
125  THttpCallArg arg;
126  arg.SetPathAndFileName(request_info->uri); // path and file name
127  arg.SetQuery(request_info->query_string); // query arguments
128  arg.SetWSId(TString::Hash((void *)conn, sizeof(void *)));
129  arg.SetMethod("WS_DATA");
130 
131  arg.SetPostData(data, len, kTRUE); // make copy of original data
132 
133  serv->ExecuteHttp(&arg);
134 
135  return 1;
136 }
137 
138 //////////////////////////////////////////////////////////////////////////
139 
140 void websocket_close_handler(const struct mg_connection *conn, void *)
141 {
142  const struct mg_request_info *request_info = mg_get_request_info(conn);
143 
144  TCivetweb *engine = (TCivetweb *)request_info->user_data;
145  if (engine == 0)
146  return;
147  THttpServer *serv = engine->GetServer();
148  if (serv == 0)
149  return;
150 
151  THttpCallArg arg;
152  arg.SetPathAndFileName(request_info->uri); // path and file name
153  arg.SetQuery(request_info->query_string); // query arguments
154  arg.SetWSId(TString::Hash((void *)conn, sizeof(void *)));
155  arg.SetMethod("WS_CLOSE");
156 
157  serv->ExecuteHttp(&arg);
158 }
159 
160 //////////////////////////////////////////////////////////////////////////
161 
162 static int log_message_handler(const struct mg_connection *conn, const char *message)
163 {
164  const struct mg_context *ctx = mg_get_context(conn);
165 
166  TCivetweb *engine = (TCivetweb *)mg_get_user_data(ctx);
167 
168  if (engine)
169  return engine->ProcessLog(message);
170 
171  // provide debug output
172  if ((gDebug > 0) || (strstr(message, "cannot bind to") != 0))
173  fprintf(stderr, "Error in <TCivetweb::Log> %s\n", message);
174 
175  return 0;
176 }
177 
178 //////////////////////////////////////////////////////////////////////////
179 
180 static int begin_request_handler(struct mg_connection *conn, void *)
181 {
182  const struct mg_request_info *request_info = mg_get_request_info(conn);
183 
184  TCivetweb *engine = (TCivetweb *)request_info->user_data;
185  if (engine == 0)
186  return 0;
187  THttpServer *serv = engine->GetServer();
188  if (serv == 0)
189  return 0;
190 
191  THttpCallArg arg;
192 
193  TString filename;
194 
195  Bool_t execres = kTRUE, debug = engine->IsDebugMode();
196 
197  if (!debug && serv->IsFileRequested(request_info->uri, filename)) {
198  if ((filename.Index(".js") != kNPOS) || (filename.Index(".css") != kNPOS)) {
199  Int_t length = 0;
200  char *buf = THttpServer::ReadFileContent(filename.Data(), length);
201  if (buf == 0) {
202  arg.Set404();
203  } else {
205  arg.SetBinData(buf, length);
206  arg.AddHeader("Cache-Control", "max-age=3600");
207  arg.SetZipping(2);
208  }
209  } else {
210  arg.SetFile(filename.Data());
211  }
212  } else {
213  arg.SetPathAndFileName(request_info->uri); // path and file name
214  arg.SetQuery(request_info->query_string); // query arguments
215  arg.SetTopName(engine->GetTopName());
216  arg.SetMethod(request_info->request_method); // method like GET or POST
217  if (request_info->remote_user != 0)
218  arg.SetUserName(request_info->remote_user);
219 
220  TString header;
221  for (int n = 0; n < request_info->num_headers; n++)
222  header.Append(
223  TString::Format("%s: %s\r\n", request_info->http_headers[n].name, request_info->http_headers[n].value));
224  arg.SetRequestHeader(header);
225 
226  const char *len = mg_get_header(conn, "Content-Length");
227  Int_t ilen = len != 0 ? TString(len).Atoi() : 0;
228 
229  if (ilen > 0) {
230  void *buf = malloc(ilen + 1); // one byte more for null-termination
231  Int_t iread = mg_read(conn, buf, ilen);
232  if (iread == ilen)
233  arg.SetPostData(buf, ilen);
234  else
235  free(buf);
236  }
237 
238  if (debug) {
239  TString cont;
240  cont.Append("<title>Civetweb echo</title>");
241  cont.Append("<h1>Civetweb echo</h1>\n");
242 
243  static int count = 0;
244 
245  cont.Append(TString::Format("Request %d:<br/>\n<pre>\n", ++count));
246  cont.Append(TString::Format(" Method : %s\n", arg.GetMethod()));
247  cont.Append(TString::Format(" PathName : %s\n", arg.GetPathName()));
248  cont.Append(TString::Format(" FileName : %s\n", arg.GetFileName()));
249  cont.Append(TString::Format(" Query : %s\n", arg.GetQuery()));
250  cont.Append(TString::Format(" PostData : %ld\n", arg.GetPostDataLength()));
251  if (arg.GetUserName())
252  cont.Append(TString::Format(" User : %s\n", arg.GetUserName()));
253 
254  cont.Append("</pre><p>\n");
255 
256  cont.Append("Environment:<br/>\n<pre>\n");
257  for (int n = 0; n < request_info->num_headers; n++)
258  cont.Append(
259  TString::Format(" %s = %s\n", request_info->http_headers[n].name, request_info->http_headers[n].value));
260  cont.Append("</pre><p>\n");
261 
262  arg.SetContentType("text/html");
263 
264  arg.SetContent(cont);
265 
266  } else {
267  execres = serv->ExecuteHttp(&arg);
268  }
269  }
270 
271  if (!execres || arg.Is404()) {
272  TString hdr;
273  arg.FillHttpHeader(hdr, "HTTP/1.1");
274  mg_printf(conn, "%s", hdr.Data());
275  } else if (arg.IsFile()) {
276  mg_send_file(conn, (const char *)arg.GetContent());
277  } else {
278 
279  Bool_t dozip = arg.GetZipping() > 0;
280  switch (arg.GetZipping()) {
281  case 2:
282  if (arg.GetContentLength() < 10000) {
283  dozip = kFALSE;
284  break;
285  }
286  case 1:
287  // check if request header has Accept-Encoding
288  dozip = kFALSE;
289  for (int n = 0; n < request_info->num_headers; n++) {
290  TString name = request_info->http_headers[n].name;
291  if (name.Index("Accept-Encoding", 0, TString::kIgnoreCase) != 0)
292  continue;
293  TString value = request_info->http_headers[n].value;
294  dozip = (value.Index("gzip", 0, TString::kIgnoreCase) != kNPOS);
295  break;
296  }
297 
298  break;
299  case 3: dozip = kTRUE; break;
300  }
301 
302  if (dozip)
303  arg.CompressWithGzip();
304 
305  TString hdr;
306  arg.FillHttpHeader(hdr, "HTTP/1.1");
307  mg_printf(conn, "%s", hdr.Data());
308 
309  if (arg.GetContentLength() > 0)
310  mg_write(conn, arg.GetContent(), (size_t)arg.GetContentLength());
311  }
312 
313  // Returning non-zero tells civetweb that our function has replied to
314  // the client, and civetweb should not send client any more data.
315  return 1;
316 }
317 
318 //////////////////////////////////////////////////////////////////////////
319 // //
320 // TCivetweb //
321 // //
322 // http server implementation, based on civetweb embedded server //
323 // It is default kind of engine, created for THttpServer //
324 // Currently v1.8 from https://github.com/civetweb/civetweb is used //
325 // //
326 // Following additional options can be specified: //
327 // top=foldername - name of top folder, seen in the browser //
328 // thrds=N - use N threads to run civetweb server (default 5) //
329 // auth_file - global authentication file //
330 // auth_domain - domain name, used for authentication //
331 // //
332 // Example: //
333 // new THttpServer("http:8080?top=MyApp&thrds=3"); //
334 // //
335 // Authentication: //
336 // When auth_file and auth_domain parameters are specified, access //
337 // to running http server will be possible only after user //
338 // authentication, using so-call digest method. To generate //
339 // authentication file, htdigest routine should be used: //
340 // //
341 // [shell] htdigest -c .htdigest domain_name user //
342 // //
343 // When creating server, parameters should be: //
344 // //
345 // new THttpServer("http:8080?auth_file=.htdigets&auth_domain=domain_name"); //
346 // //
347 //////////////////////////////////////////////////////////////////////////
348 
350 
351 ////////////////////////////////////////////////////////////////////////////////
352 /// constructor
353 
355  : THttpEngine("civetweb", "compact embedded http server"), fCtx(0), fCallbacks(0), fTopName(), fDebug(kFALSE)
356 {
357 }
358 
359 ////////////////////////////////////////////////////////////////////////////////
360 /// destructor
361 
363 {
364  if (fCtx != 0)
365  mg_stop((struct mg_context *)fCtx);
366  if (fCallbacks != 0)
367  free(fCallbacks);
368  fCtx = 0;
369  fCallbacks = 0;
370 }
371 
372 ////////////////////////////////////////////////////////////////////////////////
373 /// process civetweb log message, can be used to detect critical errors
374 
375 Int_t TCivetweb::ProcessLog(const char *message)
376 {
377  if ((gDebug > 0) || (strstr(message, "cannot bind to") != 0))
378  Error("Log", "%s", message);
379 
380  return 0;
381 }
382 
383 ////////////////////////////////////////////////////////////////////////////////
384 /// Creates embedded civetweb server
385 /// As main argument, http port should be specified like "8090".
386 /// Or one can provide combination of ipaddress and portnumber like 127.0.0.1:8090
387 /// Extra parameters like in URL string could be specified after '?' mark:
388 /// thrds=N - there N is number of threads used by the civetweb (default is 5)
389 /// top=name - configure top name, visible in the web browser
390 /// auth_file=filename - authentication file name, created with htdigets utility
391 /// auth_domain=domain - authentication domain
392 /// websocket_timeout=tm - set web sockets timeout in seconds (default 300)
393 /// loopback - bind specified port to loopback 127.0.0.1 address
394 /// debug - enable debug mode, server always returns html page with request info
395 /// log=filename - configure civetweb log file
396 
397 Bool_t TCivetweb::Create(const char *args)
398 {
399  fCallbacks = malloc(sizeof(struct mg_callbacks));
400  memset(fCallbacks, 0, sizeof(struct mg_callbacks));
401  //((struct mg_callbacks *) fCallbacks)->begin_request = begin_request_handler;
402  ((struct mg_callbacks *)fCallbacks)->log_message = log_message_handler;
403  TString sport = "8080", num_threads = "5", websocket_timeout = "300000";
404  TString auth_file, auth_domain, log_file, ssl_cert;
405 
406  // extract arguments
407  if ((args != 0) && (strlen(args) > 0)) {
408 
409  // first extract port number
410  sport = "";
411  while ((*args != 0) && (*args != '?') && (*args != '/'))
412  sport.Append(*args++);
413 
414  // than search for extra parameters
415  while ((*args != 0) && (*args != '?'))
416  args++;
417 
418  if (*args == '?') {
419  TUrl url(TString::Format("http://localhost/folder%s", args));
420 
421  if (url.IsValid()) {
422  url.ParseOptions();
423 
424  const char *top = url.GetValueFromOptions("top");
425  if (top != 0)
426  fTopName = top;
427 
428  const char *log = url.GetValueFromOptions("log");
429  if (log != 0)
430  log_file = log;
431 
432  Int_t thrds = url.GetIntValueFromOptions("thrds");
433  if (thrds > 0)
434  num_threads.Form("%d", thrds);
435 
436  const char *afile = url.GetValueFromOptions("auth_file");
437  if (afile != 0)
438  auth_file = afile;
439 
440  const char *adomain = url.GetValueFromOptions("auth_domain");
441  if (adomain != 0)
442  auth_domain = adomain;
443 
444  const char *sslc = url.GetValueFromOptions("ssl_cert");
445  if (sslc != 0)
446  ssl_cert = sslc;
447 
448  Int_t wtmout = url.GetIntValueFromOptions("websocket_timeout");
449  if (wtmout > 0)
450  websocket_timeout.Format("%d", wtmout * 1000);
451 
452  if (url.HasOption("debug"))
453  fDebug = kTRUE;
454 
455  if (url.HasOption("loopback") && (sport.Index(":") == kNPOS))
456  sport = TString("127.0.0.1:") + sport;
457 
458  if (GetServer() && url.HasOption("cors")) {
459  const char *cors = url.GetValueFromOptions("cors");
460  GetServer()->SetCors(cors && *cors ? cors : "*");
461  }
462  }
463  }
464  }
465 
466  const char *options[20];
467  int op(0);
468 
469  Info("Create", "Starting HTTP server on port %s", sport.Data());
470 
471  options[op++] = "listening_ports";
472  options[op++] = sport.Data();
473  options[op++] = "num_threads";
474  options[op++] = num_threads.Data();
475  options[op++] = "websocket_timeout_ms";
476  options[op++] = websocket_timeout.Data();
477 
478  if ((auth_file.Length() > 0) && (auth_domain.Length() > 0)) {
479  options[op++] = "global_auth_file";
480  options[op++] = auth_file.Data();
481  options[op++] = "authentication_domain";
482  options[op++] = auth_domain.Data();
483  }
484 
485  if (log_file.Length() > 0) {
486  options[op++] = "error_log_file";
487  options[op++] = log_file.Data();
488  }
489 
490  if (ssl_cert.Length() > 0) {
491  options[op++] = "ssl_certificate";
492  options[op++] = ssl_cert.Data();
493  }
494 
495  options[op++] = 0;
496 
497  // Start the web server.
498  fCtx = mg_start((struct mg_callbacks *)fCallbacks, this, options);
499 
500  if (fCtx == 0)
501  return kFALSE;
502 
503  mg_set_request_handler((struct mg_context *)fCtx, "/", begin_request_handler, 0);
504 
505  mg_set_websocket_handler((struct mg_context *)fCtx, "**root.websocket$", websocket_connect_handler,
507 
508  return kTRUE;
509 }
const char * GetFileName() const
returns file name from request URL
Definition: THttpCallArg.h:136
void SetZipping(Int_t kind)
Set kind of content zipping 0 - none 1 - only when supported in request header 2 - if supported and c...
Definition: THttpCallArg.h:192
const char * remote_user
Definition: civetweb.h:68
void SetRequestHeader(const char *h)
set full set of request header
Definition: THttpCallArg.h:100
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
TString fTopName
! name of top item
Definition: TCivetweb.h:22
void SetCors(const char *domain="*")
Enable CORS header to ProcessRequests() responses Specified location (typically "*") add as "Access-C...
Definition: THttpServer.h:77
const char * uri
Definition: civetweb.h:64
void websocket_ready_handler(struct mg_connection *conn, void *)
Definition: TCivetweb.cxx:82
void SetWSHandle(TNamed *handle)
assign websocket handle with HTTP call
const Ssiz_t kNPOS
Definition: RtypesCore.h:111
This class represents a WWW compatible URL.
Definition: TUrl.h:35
int mg_read(struct mg_connection *conn, void *buf, size_t len)
Definition: civetweb.c:4146
void mg_stop(struct mg_context *ctx)
Definition: civetweb.c:12800
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:585
Basic string class.
Definition: TString.h:125
virtual Bool_t Create(const char *args)
Creates embedded civetweb server As main argument, http port should be specified like "8090"...
Definition: TCivetweb.cxx:397
const char * GetPathName() const
returns path name from request URL
Definition: THttpCallArg.h:133
void SetQuery(const char *q)
set request query
Definition: THttpCallArg.h:85
int Int_t
Definition: RtypesCore.h:41
struct mg_request_info::mg_header http_headers[64]
bool Bool_t
Definition: RtypesCore.h:59
virtual void Send(const void *buf, int len)=0
#define malloc
Definition: civetweb.c:818
const char * GetQuery() const
returns request query (string after ? in request URL)
Definition: THttpCallArg.h:142
Bool_t IsValid() const
Definition: TUrl.h:82
Bool_t fDebug
! debug mode
Definition: TCivetweb.h:23
const char * GetTopName() const
Definition: TCivetweb.h:31
void SetContentType(const char *typ)
set content type like "text/xml" or "application/json"
Definition: THttpCallArg.h:147
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition: TString.cxx:616
void SetUserName(const char *n)
set name of authenticated user
Definition: THttpCallArg.h:82
void * fCallbacks
! call-back table for civetweb webserver
Definition: TCivetweb.h:21
THttpServer * GetServer() const
Returns pointer to THttpServer associated with engine.
Definition: THttpEngine.h:39
void SetContent(const char *c)
Set content directly.
Definition: THttpCallArg.h:183
void SetPostData(void *data, Long_t length, Bool_t make_copy=kFALSE)
set data, posted with the request buffer should be allocated with malloc(length+1) call...
void SetTopName(const char *topname)
set engine-specific top-name
Definition: THttpCallArg.h:71
void websocket_close_handler(const struct mg_connection *conn, void *)
Definition: TCivetweb.cxx:140
const char * request_method
Definition: civetweb.h:58
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2365
void SetPathAndFileName(const char *fullpath)
set complete path of requested http element For instance, it could be "/folder/subfolder/get.bin" Here "/folder/subfolder/" is element path and "get.bin" requested file.
virtual ~TCivetweb()
destructor
Definition: TCivetweb.cxx:362
void mg_set_request_handler(struct mg_context *ctx, const char *uri, mg_request_handler handler, void *cbdata)
Definition: civetweb.c:9566
void Set404()
mark reply as 404 error - page/request not exists or refused
Definition: THttpCallArg.h:150
Int_t ProcessLog(const char *message)
process civetweb log message, can be used to detect critical errors
Definition: TCivetweb.cxx:375
int websocket_connect_handler(const struct mg_connection *conn, void *)
Definition: TCivetweb.cxx:56
TString & Append(const char *cs)
Definition: TString.h:495
const char * GetUserName() const
return authenticated user name (0 - when no authentication)
Definition: THttpCallArg.h:139
void mg_send_file(struct mg_connection *conn, const char *path)
Definition: civetweb.c:6674
const char * GetValueFromOptions(const char *key) const
Return a value for a given key from the URL options.
Definition: TUrl.cxx:649
int mg_printf(struct mg_connection *conn, const char *fmt,...)
Definition: civetweb.c:4400
void SetBinData(void *data, Long_t length)
set binary data, which will be returned as reply body
virtual UInt_t GetId() const =0
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
Ssiz_t Length() const
Definition: TString.h:386
struct mg_context * mg_start(const struct mg_callbacks *callbacks, void *user_data, const char **options)
Definition: civetweb.c:12875
int mg_write(struct mg_connection *conn, const void *buf, size_t len)
Definition: civetweb.c:4235
Bool_t ExecuteHttp(THttpCallArg *arg)
Execute HTTP request.
const Bool_t kFALSE
Definition: RtypesCore.h:88
const void * GetContent() const
Definition: THttpCallArg.h:215
#define ClassImp(name)
Definition: Rtypes.h:359
const char * mg_get_header(const struct mg_connection *conn, const char *name)
Definition: civetweb.c:2063
static int log_message_handler(const struct mg_connection *conn, const char *message)
Definition: TCivetweb.cxx:162
CIVETWEB_API int mg_websocket_write(struct mg_connection *conn, int opcode, const char *data, size_t data_len)
void * mg_get_user_data(const struct mg_context *ctx)
Definition: civetweb.c:1755
void SetWSId(UInt_t id)
set web-socket id
Definition: THttpCallArg.h:94
TCivetweb()
constructor
Definition: TCivetweb.cxx:354
void SetMethod(const char *method)
set request method kind like GET or POST
Definition: THttpCallArg.h:68
#define free
Definition: civetweb.c:821
void ParseOptions() const
Parse URL options into a key/value map.
Definition: TUrl.cxx:618
void * user_data
Definition: civetweb.h:81
Bool_t IsDebugMode() const
Definition: TCivetweb.h:33
static const char * GetMimeType(const char *path)
Guess mime type base on file extension.
int websocket_data_handler(struct mg_connection *conn, int, char *data, size_t len, void *)
Definition: TCivetweb.cxx:106
const struct mg_request_info * mg_get_request_info(const struct mg_connection *conn)
Definition: civetweb.c:1972
void AddHeader(const char *name, const char *value)
Set name: value pair to reply header Content-Type field handled separately - one should use SetConten...
static char * ReadFileContent(const char *filename, Int_t &len)
Reads content of file from the disk.
Bool_t IsFile() const
Definition: THttpCallArg.h:207
Bool_t Is404() const
Definition: THttpCallArg.h:206
void SetFile(const char *filename=0)
indicate that http request should response with file content
Definition: THttpCallArg.h:156
R__EXTERN Int_t gDebug
Definition: Rtypes.h:86
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1975
virtual void ClearHandle()=0
Int_t GetIntValueFromOptions(const char *key) const
Return a value for a given key from the URL options as an Int_t, a missing key returns -1...
Definition: TUrl.cxx:661
const char * query_string
Definition: civetweb.h:66
static int begin_request_handler(struct mg_connection *conn, void *)
Definition: TCivetweb.cxx:180
Int_t GetZipping() const
return kind of content zipping
Definition: THttpCallArg.h:195
void mg_set_websocket_handler(struct mg_context *ctx, const char *uri, mg_websocket_connect_handler connect_handler, mg_websocket_ready_handler ready_handler, mg_websocket_data_handler data_handler, mg_websocket_close_handler close_handler, void *cbdata)
Definition: civetweb.c:9586
Long_t GetPostDataLength() const
return length of posted with request data
Definition: THttpCallArg.h:127
const Bool_t kTRUE
Definition: RtypesCore.h:87
Bool_t HasOption(const char *key) const
Returns true if the given key appears in the URL options list.
Definition: TUrl.cxx:672
const Int_t n
Definition: legend1.C:16
const char * GetMethod() const
returns request method like GET or POST
Definition: THttpCallArg.h:115
Bool_t IsFileRequested(const char *uri, TString &res) const
Check if file is requested, thread safe.
char name[80]
Definition: TGX11.cxx:109
double log(double)
struct mg_context * mg_get_context(const struct mg_connection *conn)
Definition: civetweb.c:1748
void * fCtx
! civetweb context
Definition: TCivetweb.h:20
Bool_t CompressWithGzip()
compress reply data with gzip compression
void FillHttpHeader(TString &buf, const char *header=0)
fill HTTP header
const char * Data() const
Definition: TString.h:345
Long_t GetContentLength() const
Definition: THttpCallArg.h:213