00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef QORE_HTTP_CLIENT_H_
00025 #define QORE_HTTP_CLIENT_H_
00026
00027 #include <qore/common.h>
00028 #include <qore/AbstractPrivateData.h>
00029 #include <qore/QoreThreadLock.h>
00030 #include <qore/QoreSocket.h>
00031
00032 #define HTTPCLIENT_DEFAULT_PORT 80
00033 #define HTTPCLIENT_DEFAULT_HOST "localhost"
00034
00035 #define HTTPCLIENT_DEFAULT_TIMEOUT 300000
00036
00037 #define HTTPCLIENT_DEFAULT_MAX_REDIRECTS 5
00038
00039 class Queue;
00040
00042
00044 class QoreHTTPClient : public AbstractPrivateData {
00045 private:
00047 struct qore_qtc_private *priv;
00048
00049
00050 DLLLOCAL int set_url_unlocked(const char *url, ExceptionSink *xsink);
00051
00052 DLLLOCAL int set_proxy_url_unlocked(const char *url, ExceptionSink *xsink);
00053 DLLLOCAL QoreHashNode *send_internal(const char *meth, const char *mpath, const QoreHashNode *headers, const void *data, unsigned size, bool getbody, QoreHashNode *info, ExceptionSink *xsink, bool suppress_content_length = false);
00054 DLLLOCAL void setSocketPath();
00055 DLLLOCAL const char *getMsgPath(const char *mpath, QoreString &pstr);
00056 DLLLOCAL QoreHashNode *getResponseHeader(const char *meth, const char *mpath, const QoreHashNode &nh, const void *data, unsigned size, int &code, bool suppress_content_length, QoreHashNode *info, ExceptionSink *xsink);
00057 DLLLOCAL AbstractQoreNode *getHostHeaderValue();
00058
00060 DLLLOCAL QoreHTTPClient(const QoreHTTPClient&);
00061
00063 DLLLOCAL QoreHTTPClient& operator=(const QoreHTTPClient&);
00064
00065 protected:
00066 DLLEXPORT void lock();
00067 DLLEXPORT void unlock();
00068
00069 public:
00071 DLLEXPORT QoreHTTPClient();
00072
00074 DLLEXPORT virtual ~QoreHTTPClient();
00075
00077
00094 DLLEXPORT int setOptions(const QoreHashNode *opts, ExceptionSink* xsink);
00095
00097
00099 DLLEXPORT void setDefaultPort(int prt);
00100
00102
00104 DLLEXPORT void setDefaultPath(const char *pth);
00105
00107
00109 DLLEXPORT void addProtocol(const char *prot, int port, bool ssl = false);
00110
00112 DLLEXPORT void setTimeout(int to);
00113
00115 DLLEXPORT int getTimeout() const;
00116
00118 DLLEXPORT void setEncoding(const QoreEncoding *qe);
00119
00121 DLLEXPORT const QoreEncoding *getEncoding() const;
00122
00124
00129 DLLEXPORT int setHTTPVersion(const char* version, ExceptionSink* xsink);
00130
00132
00135 DLLEXPORT const char* getHTTPVersion() const;
00136
00138
00141 DLLEXPORT void setHTTP11(bool h11);
00142
00144 DLLEXPORT bool isHTTP11() const;
00145
00147
00151 DLLEXPORT int setURL(const char *url, ExceptionSink *xsink);
00152
00154
00157 DLLEXPORT QoreStringNode *getURL();
00158
00160
00164 DLLEXPORT int setProxyURL(const char *proxy, ExceptionSink *xsink);
00165
00167
00170 DLLEXPORT QoreStringNode *getProxyURL();
00171
00173 DLLEXPORT void clearProxyURL();
00174
00176 DLLEXPORT void setSecure(bool is_secure);
00177
00179 DLLEXPORT bool isSecure() const;
00180
00182 DLLEXPORT void setProxySecure(bool is_secure);
00183
00185 DLLEXPORT bool isProxySecure() const;
00186
00188 DLLEXPORT void setMaxRedirects(int max);
00189
00191 DLLEXPORT int getMaxRedirects() const;
00192
00194 DLLEXPORT long verifyPeerCertificate();
00195
00197
00200 DLLEXPORT const char *getSSLCipherName();
00201
00203
00206 DLLEXPORT const char *getSSLCipherVersion();
00207
00209
00211 DLLEXPORT int connect(ExceptionSink *xsink);
00212
00214 DLLEXPORT void disconnect();
00215
00217
00228 DLLEXPORT QoreHashNode *send(const char *meth, const char *path, const QoreHashNode *headers, const void *data, unsigned size, bool getbody, QoreHashNode *info, ExceptionSink *xsink);
00229
00231
00238 DLLEXPORT AbstractQoreNode *get(const char *path, const QoreHashNode *headers, QoreHashNode *info, ExceptionSink *xsink);
00239
00241
00247 DLLEXPORT QoreHashNode *head(const char *path, const QoreHashNode *headers, QoreHashNode *info, ExceptionSink *xsink);
00248
00250
00259 DLLEXPORT AbstractQoreNode *post(const char *path, const QoreHashNode *headers, const void *data, unsigned size, QoreHashNode *info, ExceptionSink *xsink);
00260
00262
00266 DLLEXPORT void setDefaultHeaderValue(const char *header, const char *val);
00267
00269
00272 DLLEXPORT virtual void deref(ExceptionSink *xsink);
00273
00275
00278 DLLEXPORT void setConnectTimeout(int ms);
00279
00281
00284 DLLEXPORT int getConnectTimeout() const;
00285
00287
00296 DLLEXPORT int setNoDelay(bool nodelay);
00297
00299 DLLEXPORT bool getNoDelay() const;
00300
00302 DLLEXPORT bool isConnected() const;
00303
00304 DLLLOCAL static void static_init();
00305
00307 DLLLOCAL void setEventQueue(Queue *cbq, ExceptionSink *xsink);
00308
00309 DLLLOCAL void cleanup(ExceptionSink *xsink);
00310 };
00311
00312 #endif
00313
00314
00315