00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef QORE_HTTP_CLIENT_H_
00024 #define QORE_HTTP_CLIENT_H_
00025
00026 #include <qore/common.h>
00027 #include <qore/AbstractPrivateData.h>
00028 #include <qore/QoreThreadLock.h>
00029 #include <qore/QoreSocket.h>
00030
00031 #define HTTPCLIENT_DEFAULT_PORT 80
00032 #define HTTPCLIENT_DEFAULT_HOST "localhost"
00033
00034 #define HTTPCLIENT_DEFAULT_TIMEOUT 300000
00035
00036 #define HTTPCLIENT_DEFAULT_MAX_REDIRECTS 5
00037
00038 class Queue;
00039
00041
00043 class QoreHTTPClient : public AbstractPrivateData {
00044 private:
00046 struct qore_qtc_private *priv;
00047
00048
00049 DLLLOCAL int set_url_unlocked(const char *url, ExceptionSink *xsink);
00050
00051 DLLLOCAL int set_proxy_url_unlocked(const char *url, ExceptionSink *xsink);
00052 DLLLOCAL QoreHashNode *send_internal(const char *meth, const char *mpath, const QoreHashNode *headers, const void *data, unsigned size, bool getbody, QoreHashNode *info, ExceptionSink *xsink);
00053 DLLLOCAL void setSocketPath();
00054 DLLLOCAL const char *getMsgPath(const char *mpath, QoreString &pstr);
00055 DLLLOCAL QoreHashNode *getResponseHeader(const char *meth, const char *mpath, const QoreHashNode &nh, const void *data, unsigned size, int &code, ExceptionSink *xsink);
00056 DLLLOCAL AbstractQoreNode *getHostHeaderValue();
00057
00059 DLLLOCAL QoreHTTPClient(const QoreHTTPClient&);
00060
00062 DLLLOCAL QoreHTTPClient& operator=(const QoreHTTPClient&);
00063
00064 protected:
00065 DLLEXPORT void lock();
00066 DLLEXPORT void unlock();
00067
00068 public:
00070 DLLEXPORT QoreHTTPClient();
00071
00073 DLLEXPORT virtual ~QoreHTTPClient();
00074
00076
00093 DLLEXPORT int setOptions(const QoreHashNode *opts, ExceptionSink* xsink);
00094
00096
00098 DLLEXPORT void setDefaultPort(int prt);
00099
00101
00103 DLLEXPORT void setDefaultPath(const char *pth);
00104
00106
00108 DLLEXPORT void addProtocol(const char *prot, int port, bool ssl = false);
00109
00111 DLLEXPORT void setTimeout(int to);
00112
00114 DLLEXPORT int getTimeout() const;
00115
00117 DLLEXPORT void setEncoding(const QoreEncoding *qe);
00118
00120 DLLEXPORT const QoreEncoding *getEncoding() const;
00121
00123
00128 DLLEXPORT int setHTTPVersion(const char* version, ExceptionSink* xsink);
00129
00131
00134 DLLEXPORT const char* getHTTPVersion() const;
00135
00137
00140 DLLEXPORT void setHTTP11(bool h11);
00141
00143 DLLEXPORT bool isHTTP11() const;
00144
00146
00150 DLLEXPORT int setURL(const char *url, ExceptionSink *xsink);
00151
00153
00156 DLLEXPORT QoreStringNode *getURL();
00157
00159
00163 DLLEXPORT int setProxyURL(const char *proxy, ExceptionSink *xsink);
00164
00166
00169 DLLEXPORT QoreStringNode *getProxyURL();
00170
00172 DLLEXPORT void clearProxyURL();
00173
00175 DLLEXPORT void setSecure(bool is_secure);
00176
00178 DLLEXPORT bool isSecure() const;
00179
00181 DLLEXPORT void setProxySecure(bool is_secure);
00182
00184 DLLEXPORT bool isProxySecure() const;
00185
00187 DLLEXPORT void setMaxRedirects(int max);
00188
00190 DLLEXPORT int getMaxRedirects() const;
00191
00193 DLLEXPORT long verifyPeerCertificate();
00194
00196
00199 DLLEXPORT const char *getSSLCipherName();
00200
00202
00205 DLLEXPORT const char *getSSLCipherVersion();
00206
00208
00210 DLLEXPORT int connect(ExceptionSink *xsink);
00211
00213 DLLEXPORT void disconnect();
00214
00216
00227 DLLEXPORT QoreHashNode *send(const char *meth, const char *path, const QoreHashNode *headers, const void *data, unsigned size, bool getbody, QoreHashNode *info, ExceptionSink *xsink);
00228
00230
00237 DLLEXPORT AbstractQoreNode *get(const char *path, const QoreHashNode *headers, QoreHashNode *info, ExceptionSink *xsink);
00238
00240
00246 DLLEXPORT QoreHashNode *head(const char *path, const QoreHashNode *headers, QoreHashNode *info, ExceptionSink *xsink);
00247
00249
00258 DLLEXPORT AbstractQoreNode *post(const char *path, const QoreHashNode *headers, const void *data, unsigned size, QoreHashNode *info, ExceptionSink *xsink);
00259
00261
00265 DLLEXPORT void setDefaultHeaderValue(const char *header, const char *val);
00266
00268
00271 DLLEXPORT virtual void deref(ExceptionSink *xsink);
00272
00274
00277 DLLEXPORT void setConnectTimeout(int ms);
00278
00280
00283 DLLEXPORT int getConnectTimeout() const;
00284
00286
00295 DLLLOCAL int setNoDelay(bool nodelay);
00296
00298 DLLLOCAL bool getNoDelay() const;
00299
00300 DLLLOCAL static void static_init();
00301
00303 DLLLOCAL void setEventQueue(Queue *cbq, ExceptionSink *xsink);
00304
00305 DLLLOCAL void cleanup(ExceptionSink *xsink);
00306 };
00307
00308 #endif
00309
00310
00311