6 #include "../civetweb/civetweb.h"
20 if (engine)
return engine->
ProcessLog(message);
23 if ((
gDebug>0) || (strstr(message,
"cannot bind to")!=0))
24 fprintf(stderr,
"Error in <TCivetweb::Log> %s\n",message);
33 if (engine == 0)
return 0;
35 if (serv == 0)
return 0;
54 arg.
AddHeader(
"Cache-Control",
"max-age=3600");
77 void* buf =
malloc(ilen+1);
85 cont.
Append(
"<title>Civetweb echo</title>");
86 cont.
Append(
"<h1>Civetweb echo</h1>\n");
99 cont.
Append(
"</pre><p>\n");
101 cont.
Append(
"Environment:<br/>\n<pre>\n");
104 cont.
Append(
"</pre><p>\n");
115 if (!execres || arg.
Is404()) {
119 }
else if (arg.
IsFile()) {
200 THttpEngine("civetweb", "compact embedded http server"),
224 if ((
gDebug>0) || (strstr(message,
"cannot bind to")!=0))
Error(
"Log",
"%s", message);
249 TString auth_file, auth_domain, log_file;
252 if ((args != 0) && (strlen(args) > 0)) {
256 while ((*args != 0) && (*args !=
'?') && (*args !=
'/'))
260 while ((*args != 0) && (*args !=
'?')) args++;
272 if (log != 0) log_file =
log;
275 if (thrds > 0) num_threads.
Form(
"%d", thrds);
278 if (afile != 0) auth_file = afile;
281 if (adomain != 0) auth_domain = adomain;
286 sport =
TString(
"127.0.0.1:") + sport;
291 const char *options[20];
294 Info(
"Create",
"Starting HTTP server on port %s", sport.
Data());
296 options[op++] =
"listening_ports";
297 options[op++] = sport.
Data();
298 options[op++] =
"num_threads";
299 options[op++] = num_threads.
Data();
301 if ((auth_file.
Length() > 0) && (auth_domain.
Length() > 0)) {
302 options[op++] =
"global_auth_file";
303 options[op++] = auth_file.
Data();
304 options[op++] =
"authentication_domain";
305 options[op++] = auth_domain.
Data();
308 if (log_file.
Length() > 0) {
309 options[op++] =
"error_log_file";
310 options[op++] = log_file.
Data();
void SetZipping(Int_t kind)
THttpServer * GetServer() const
void SetRequestHeader(const char *h)
Bool_t HasOption(const char *key) const
Returns true if the given key appears in the URL options list.
static int begin_request_handler(struct mg_connection *conn)
TString fTopName
call-back table for civetweb webserver
This class represents a WWW compatible URL.
int mg_read(struct mg_connection *conn, void *buf, size_t len)
Long_t GetContentLength() const
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
static const char * filename()
void mg_stop(struct mg_context *ctx)
const struct mg_context * mg_get_context(const struct mg_connection *conn)
const char * GetPathName() const
virtual Bool_t Create(const char *args)
Creates embedded civetweb server As main argument, http port should be specified like "8090"...
void SetQuery(const char *q)
struct mg_request_info::mg_header http_headers[64]
Bool_t fDebug
name of top item
void SetContentType(const char *typ)
const void * GetContent() const
void SetUserName(const char *n)
void * fCallbacks
civetweb context
void SetContent(const char *c)
const char * GetMethod() const
void SetTopName(const char *topname)
const char * Data() const
const char * request_method
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Vc_ALWAYS_INLINE void free(T *p)
Frees memory that was allocated with Vc::malloc.
void SetPostData(void *data, Long_t length)
set data, posted with the request buffer should be allocated with malloc(length+1) call...
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
const char * GetTopName() const
Int_t ProcessLog(const char *message)
process civetweb log message, can be used to detect critical errors
TString & Append(const char *cs)
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...
Int_t Atoi() const
Return integer value of string.
void mg_send_file(struct mg_connection *conn, const char *path)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
const char * GetQuery() const
int mg_printf(struct mg_connection *conn, const char *fmt,...)
Bool_t IsDebugMode() const
void SetBinData(void *data, Long_t length)
set binary data, which will be returned as reply body
const char * GetValueFromOptions(const char *key) const
Return a value for a given key from the URL options.
Double_t length(const TVector2 &v)
const char * GetFileName() const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Bool_t IsFileRequested(const char *uri, TString &res) const
Check if file is requested, thread safe.
const char * GetUserName() const
struct mg_context * mg_start(const struct mg_callbacks *callbacks, void *user_data, const char **options)
int mg_write(struct mg_connection *conn, const void *buf, size_t len)
Bool_t ExecuteHttp(THttpCallArg *arg)
Execute HTTP request.
const char * mg_get_header(const struct mg_connection *conn, const char *name)
static int log_message_handler(const struct mg_connection *conn, const char *message)
void * mg_get_user_data(const struct mg_context *ctx)
void SetMethod(const char *method)
static const char * GetMimeType(const char *path)
Guess mime type base on file extension.
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.
void SetFile(const char *filename=0)
void ParseOptions() const
Parse URL options into a key/value map.
struct mg_request_info * mg_get_request_info(struct mg_connection *conn)
Long_t GetPostDataLength() const
const char * query_string
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
ClassImp(TCivetweb) TCivetweb
constructor
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
Bool_t CompressWithGzip()
compress reply data with gzip compression
void FillHttpHeader(TString &buf, const char *header=0)
fill HTTP header