#ifndef ROOT_THttpCallArg
#define ROOT_THttpCallArg
#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TCondition
#include "TCondition.h"
#endif
class THttpServer;
class THttpCallArg : public TObject {
protected:
friend class THttpServer;
TString fTopName;
TString fMethod;
TString fPathName;
TString fFileName;
TString fUserName;
TString fQuery;
void *fPostData;
Long_t fPostDataLength;
TCondition fCond;
TString fContentType;
TString fRequestHeader;
TString fHeader;
TString fContent;
Int_t fZipping;
void *fBinData;
Long_t fBinDataLength;
Bool_t IsBinData() const
{
return fBinData && fBinDataLength > 0;
}
TString AccessHeader(TString& buf, const char* name, const char* value = 0, Bool_t doing_set = kFALSE);
TString CountHeader(const TString& buf, Int_t number = -1111) const;
public:
THttpCallArg();
~THttpCallArg();
void SetMethod(const char *method)
{
fMethod = method;
}
void SetTopName(const char *topname)
{
fTopName = topname;
}
void SetPathAndFileName(const char *fullpath);
void SetPathName(const char *p)
{
fPathName = p;
}
void SetFileName(const char *f)
{
fFileName = f;
}
void SetUserName(const char *n)
{
fUserName = n;
}
void SetQuery(const char *q)
{
fQuery = q;
}
void SetPostData(void *data, Long_t length);
void SetRequestHeader(const char* h)
{
fRequestHeader = h ? h : "";
}
Int_t NumRequestHeader() const
{
return CountHeader(fRequestHeader).Atoi();
}
TString GetRequestHeaderName(Int_t number) const
{
return CountHeader(fRequestHeader, number);
}
TString GetRequestHeader(const char* name)
{
return AccessHeader(fRequestHeader, name);
}
const char *GetTopName() const
{
return fTopName.Data();
}
const char *GetMethod() const
{
return fMethod.Data();
}
Bool_t IsPostMethod() const
{
return fMethod.CompareTo("POST")==0;
}
void* GetPostData() const
{
return fPostData;
}
Long_t GetPostDataLength() const
{
return fPostDataLength;
}
const char *GetPathName() const
{
return fPathName.Data();
}
const char *GetFileName() const
{
return fFileName.Data();
}
const char *GetUserName() const
{
return fUserName.Length() > 0 ? fUserName.Data() : 0;
}
const char *GetQuery() const
{
return fQuery.Data();
}
void SetContentType(const char *typ)
{
fContentType = typ;
}
void Set404()
{
SetContentType("_404_");
}
void SetFile(const char *filename = 0)
{
SetContentType("_file_");
if (filename != 0) fContent = filename;
}
void SetXml()
{
SetContentType("text/xml");
}
void SetJson()
{
SetContentType("application/json");
}
void AddHeader(const char *name, const char *value);
Int_t NumHeader() const
{
return CountHeader(fHeader).Atoi();
}
TString GetHeaderName(Int_t number) const
{
return CountHeader(fHeader, number);
}
TString GetHeader(const char* name);
void SetEncoding(const char *typ)
{
AccessHeader(fHeader, "Content-Encoding", typ, kTRUE);
}
void SetContent(const char *c)
{
fContent = c;
}
Bool_t CompressWithGzip();
void SetZipping(Int_t kind)
{
fZipping = kind;
}
Int_t GetZipping() const
{
return fZipping;
}
void SetExtraHeader(const char *name, const char *value)
{
AddHeader(name, value);
}
void FillHttpHeader(TString &buf, const char *header = 0);
Bool_t IsContentType(const char *typ) const
{
return fContentType == typ;
}
Bool_t Is404() const
{
return IsContentType("_404_");
}
Bool_t IsFile() const
{
return IsContentType("_file_");
}
const char *GetContentType() const
{
return fContentType.Data();
}
void SetBinData(void *data, Long_t length);
Long_t GetContentLength() const
{
return IsBinData() ? fBinDataLength : fContent.Length();
}
const void *GetContent() const
{
return IsBinData() ? fBinData : fContent.Data();
}
ClassDef(THttpCallArg, 0)
};
#endif