QoreHttpClientObject.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreHttpClientObject.h
Qore Programming Language
Copyright (C) 2006 - 2022 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef QORE_HTTP_CLIENT_OBJECT_H_
#define QORE_HTTP_CLIENT_OBJECT_H_
#include <qore/common.h>
#include <qore/QoreSocketObject.h>
#include <qore/OutputStream.h>
#define HTTPCLIENT_DEFAULT_PORT 80
#define HTTPCLIENT_DEFAULT_HOST "localhost"
#define HTTPCLIENT_DEFAULT_TIMEOUT 300000
#define HTTPCLIENT_DEFAULT_MAX_REDIRECTS 5
class Queue;
class QoreHttpClientObject : public QoreSocketObject {
private:
struct qore_httpclient_priv* http_priv;
DLLLOCAL QoreHttpClientObject(const QoreHttpClientObject&);
DLLLOCAL QoreHttpClientObject& operator=(const QoreHttpClientObject&);
protected:
DLLEXPORT void lock();
DLLEXPORT void unlock();
public:
DLLEXPORT QoreHttpClientObject();
DLLEXPORT virtual ~QoreHttpClientObject();
DLLEXPORT int setOptions(const QoreHashNode* opts, ExceptionSink* xsink);
DLLEXPORT void setDefaultPort(int prt);
DLLEXPORT void setDefaultPath(const char* pth);
DLLEXPORT const char* getDefaultPath() const;
DLLEXPORT const char* getConnectionPath() const;
DLLEXPORT void setConnectionPath(const char* path);
DLLEXPORT void addProtocol(const char* prot, int port, bool ssl = false);
DLLEXPORT void setTimeout(int to);
DLLEXPORT int getTimeout() const;
DLLEXPORT void setEncoding(const QoreEncoding* qe);
DLLEXPORT const QoreEncoding* getEncoding() const;
DLLEXPORT int setHTTPVersion(const char* version, ExceptionSink* xsink);
DLLEXPORT const char* getHTTPVersion() const;
DLLEXPORT void setHTTP11(bool h11);
DLLEXPORT bool isHTTP11() const;
DLLEXPORT int setURL(const char* url, ExceptionSink* xsink);
DLLEXPORT QoreStringNode* getURL();
DLLEXPORT void setUserPassword(const char* user, const char* pass);
DLLEXPORT void clearUserPassword();
DLLEXPORT int setProxyURL(const char* proxy, ExceptionSink* xsink);
DLLEXPORT QoreStringNode* getProxyURL();
DLLEXPORT void clearProxyURL();
DLLEXPORT void setProxyUserPassword(const char* user, const char* pass);
DLLEXPORT void clearProxyUserPassword();
DLLEXPORT void setSecure(bool is_secure);
DLLEXPORT bool isSecure() const;
DLLEXPORT void setProxySecure(bool is_secure);
DLLEXPORT bool isProxySecure() const;
DLLEXPORT void setMaxRedirects(int max);
DLLEXPORT int getMaxRedirects() const;
DLLEXPORT int connect(ExceptionSink* xsink);
DLLEXPORT void disconnect();
DLLEXPORT QoreHashNode* send(const char* meth, const char* path, const QoreHashNode* headers, const void* data,
unsigned size, bool getbody, QoreHashNode* info, ExceptionSink* xsink);
DLLEXPORT QoreHashNode* send(const char* meth, const char* path, const QoreHashNode* headers,
const QoreStringNode& body, bool getbody, QoreHashNode* info, ExceptionSink* xsink);
DLLEXPORT QoreHashNode* sendWithSendCallback(const char* meth, const char* mpath, const QoreHashNode* headers,
const ResolvedCallReferenceNode* send_callback, bool getbody, QoreHashNode* info, int timeout_ms,
ExceptionSink* xsink);
DLLEXPORT void sendWithRecvCallback(const char* meth, const char* mpath, const QoreHashNode* headers,
const void* data, unsigned size, bool getbody, QoreHashNode* info, int timeout_ms,
const ResolvedCallReferenceNode* recv_callback, QoreObject* obj, ExceptionSink* xsink);
DLLEXPORT void sendWithRecvCallback(const char* meth, const char* mpath, const QoreHashNode* headers,
const QoreStringNode& body, bool getbody, QoreHashNode* info, int timeout_ms,
const ResolvedCallReferenceNode* recv_callback, QoreObject* obj, ExceptionSink* xsink);
DLLEXPORT void sendWithCallbacks(const char* meth, const char* mpath, const QoreHashNode* headers,
const ResolvedCallReferenceNode* send_callback, bool getbody, QoreHashNode* info, int timeout_ms,
const ResolvedCallReferenceNode* recv_callback, QoreObject* obj, ExceptionSink* xsink);
DLLEXPORT void sendWithOutputStream(const char* meth, const char* mpath, const QoreHashNode* headers,
const void* data, unsigned size, bool getbody, QoreHashNode* info, int timeout_ms,
const ResolvedCallReferenceNode* recv_callback, QoreObject* obj, OutputStream *os, ExceptionSink* xsink);
DLLEXPORT void sendWithOutputStream(const char* meth, const char* mpath, const QoreHashNode* headers,
const QoreStringNode& body, bool getbody, QoreHashNode* info, int timeout_ms,
const ResolvedCallReferenceNode* recv_callback, QoreObject* obj, OutputStream *os, ExceptionSink* xsink);
DLLEXPORT void sendChunked(const char* meth, const char* mpath, const QoreHashNode* headers, bool getbody,
QoreHashNode* info, int timeout_ms, const ResolvedCallReferenceNode* recv_callback, QoreObject* obj,
OutputStream *os, InputStream* is, size_t max_chunk_size, const ResolvedCallReferenceNode* trailer_callback,
ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* get(const char* path, const QoreHashNode* headers, QoreHashNode* info, ExceptionSink* xsink);
DLLEXPORT QoreHashNode* head(const char* path, const QoreHashNode* headers, QoreHashNode* info, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* post(const char* path, const QoreHashNode* headers, const void* data, unsigned size, QoreHashNode* info, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* post(const char* path, const QoreHashNode* headers, const QoreStringNode& body,
QoreHashNode* info, ExceptionSink* xsink);
DLLEXPORT void setDefaultHeaderValue(const char* header, const char* val);
DLLEXPORT void addDefaultHeaders(const QoreHashNode* hdr);
DLLEXPORT QoreHashNode* getDefaultHeaders() const;
using AbstractPrivateData::deref;
DLLEXPORT virtual void deref(ExceptionSink* xsink);
DLLEXPORT void setConnectTimeout(int ms);
DLLEXPORT int getConnectTimeout() const;
DLLEXPORT int setNoDelay(bool nodelay);
DLLEXPORT void setEventQueue(Queue* cbq, ExceptionSink* xsink);
DLLEXPORT void setEventQueue(ExceptionSink* xsink, Queue* q, QoreValue arg, bool with_data);
DLLEXPORT bool getNoDelay() const;
DLLEXPORT bool isConnected() const;
DLLEXPORT void setPersistent(ExceptionSink* xsink);
DLLEXPORT void clearWarningQueue(ExceptionSink* xsink);
DLLEXPORT void setWarningQueue(ExceptionSink* xsink, int64 warning_ms, int64 warning_bs, Queue* wq, QoreValue arg, int64 min_ms = 1000);
DLLEXPORT QoreHashNode* getUsageInfo() const;
DLLEXPORT void clearStats();
DLLEXPORT bool setErrorPassthru(bool set);
DLLEXPORT bool getErrorPassthru() const;
DLLEXPORT bool setRedirectPassthru(bool set);
DLLEXPORT bool getRedirectPassthru() const;
DLLEXPORT bool setEncodingPassthru(bool set);
DLLEXPORT bool getEncodingPassthru() const;
DLLEXPORT QoreStringNode* getHostHeaderValue() const;
DLLEXPORT void setAssumedEncoding(const char* enc);
DLLEXPORT QoreStringNode* getAssumedEncoding() const;
DLLLOCAL static void static_init();
DLLLOCAL void cleanup(ExceptionSink* xsink);
};
#endif
QoreHttpClientObject::setErrorPassthru
DLLEXPORT bool setErrorPassthru(bool set)
sets the new and returns the old error_passthru status
QoreHttpClientObject::clearProxyUserPassword
DLLEXPORT void clearProxyUserPassword()
clears the username and password for the proxy connection
QoreHttpClientObject::head
DLLEXPORT QoreHashNode * head(const char *path, const QoreHashNode *headers, QoreHashNode *info, ExceptionSink *xsink)
sends an HTTP "HEAD" method and returns the headers returned, the caller owns the QoreHashNode refere...
QoreHttpClientObject::getEncodingPassthru
DLLEXPORT bool getEncodingPassthru() const
returns the current encoding_passthru status
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
QoreHttpClientObject::getURL
DLLEXPORT QoreStringNode * getURL()
returns the connection parameters as a URL, caller owns the reference count returned ...
QoreHttpClientObject::setPersistent
DLLEXPORT void setPersistent(ExceptionSink *xsink)
temporarily disables implicit reconnections; must be called when the server is already connected ...
QoreHttpClientObject::connect
DLLEXPORT int connect(ExceptionSink *xsink)
opens a connection and returns a code giving the result
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:50
QoreHttpClientObject::getDefaultHeaders
DLLEXPORT QoreHashNode * getDefaultHeaders() const
Returns a hash of default headers to be sent with every outgoing request.
QoreHttpClientObject::isProxySecure
DLLEXPORT bool isProxySecure() const
returns the SSL proxy connection parameter flag
QoreHttpClientObject::setOptions
DLLEXPORT int setOptions(const QoreHashNode *opts, ExceptionSink *xsink)
set options with a hash, returns -1 if an exception was thrown, 0 for OK
QoreHttpClientObject::getTimeout
DLLEXPORT int getTimeout() const
returns the connection and response packet timeout value in milliseconds
QoreHttpClientObject::getConnectTimeout
DLLEXPORT int getConnectTimeout() const
returns the connect timeout in ms, negative numbers mean no timeout
QoreHttpClientObject::sendWithOutputStream
DLLEXPORT void sendWithOutputStream(const char *meth, const char *mpath, const QoreHashNode *headers, const void *data, unsigned size, bool getbody, QoreHashNode *info, int timeout_ms, const ResolvedCallReferenceNode *recv_callback, QoreObject *obj, OutputStream *os, ExceptionSink *xsink)
make an HTTP request and receive the response to an OutputStream
QoreHttpClientObject::sendChunked
DLLEXPORT void sendChunked(const char *meth, const char *mpath, const QoreHashNode *headers, bool getbody, QoreHashNode *info, int timeout_ms, const ResolvedCallReferenceNode *recv_callback, QoreObject *obj, OutputStream *os, InputStream *is, size_t max_chunk_size, const ResolvedCallReferenceNode *trailer_callback, ExceptionSink *xsink)
send a chunked HTTP message through an InputStream and receive the response to an OutputStream ...
QoreHttpClientObject::QoreHttpClientObject
DLLEXPORT QoreHttpClientObject()
creates the QoreHttpClientObject object
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
QoreHttpClientObject::setAssumedEncoding
DLLEXPORT void setAssumedEncoding(const char *enc)
sets the assumed encoding
QoreHttpClientObject::getHTTPVersion
DLLEXPORT const char * getHTTPVersion() const
returns the http version as a string (either "1.0" or "1.1")
QoreHttpClientObject::setTimeout
DLLEXPORT void setTimeout(int to)
sets the connection and response packet timeout value in milliseconds
QoreHttpClientObject::setDefaultPath
DLLEXPORT void setDefaultPath(const char *pth)
sets the default path
QoreHttpClientObject::setEncodingPassthru
DLLEXPORT bool setEncodingPassthru(bool set)
sets the new and returns the old encoding_passthru status
QoreHttpClientObject::setProxyURL
DLLEXPORT int setProxyURL(const char *proxy, ExceptionSink *xsink)
sets the proxy URL
QoreHttpClientObject::getConnectionPath
DLLEXPORT const char * getConnectionPath() const
returns the current connection path or 0 if none is set
QoreHttpClientObject::addProtocol
DLLEXPORT void addProtocol(const char *prot, int port, bool ssl=false)
adds a protocol
OutputStream
Interface for private data of output streams.
Definition: OutputStream.h:44
QoreHttpClientObject::~QoreHttpClientObject
virtual DLLEXPORT ~QoreHttpClientObject()
destroys the object and frees all associated memory
QoreHttpClientObject::setURL
DLLEXPORT int setURL(const char *url, ExceptionSink *xsink)
sets the connection URL
QoreHttpClientObject::setDefaultPort
DLLEXPORT void setDefaultPort(int prt)
sets the default port
QoreStringNode
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
QoreHttpClientObject::isSecure
DLLEXPORT bool isSecure() const
returns the SSL connection parameter flag
QoreHttpClientObject::setHTTP11
DLLEXPORT void setHTTP11(bool h11)
sets or clears HTTP 1.1 protocol compliance
QoreHttpClientObject::setConnectTimeout
DLLEXPORT void setConnectTimeout(int ms)
sets the connect timeout in ms
QoreHttpClientObject::post
DLLEXPORT AbstractQoreNode * post(const char *path, const QoreHashNode *headers, const void *data, unsigned size, QoreHashNode *info, ExceptionSink *xsink)
sends an HTTP "POST" message to the remote server and returns the message body of the response...
QoreHttpClientObject::setDefaultHeaderValue
DLLEXPORT void setDefaultHeaderValue(const char *header, const char *val)
sets the value of a default header to send with every outgoing message
QoreHttpClientObject::getNoDelay
DLLEXPORT bool getNoDelay() const
returns the value of the TCP_NODELAY flag on the object
QoreHttpClientObject::setUserPassword
DLLEXPORT void setUserPassword(const char *user, const char *pass)
sets the username and password for the connection
AbstractPrivateData::deref
virtual DLLLOCAL void deref()
decrements the reference count of the object without the possibility of throwing a Qore-language exce...
Definition: AbstractPrivateData.h:65
QoreHttpClientObject::setRedirectPassthru
DLLEXPORT bool setRedirectPassthru(bool set)
sets the new and returns the old redirect_passthru status
QoreHttpClientObject::addDefaultHeaders
DLLEXPORT void addDefaultHeaders(const QoreHashNode *hdr)
Sets the value of multiple headers to send with every outgoing message.
QoreHttpClientObject::setHTTPVersion
DLLEXPORT int setHTTPVersion(const char *version, ExceptionSink *xsink)
sets the http version from a string
QoreHttpClientObject::setMaxRedirects
DLLEXPORT void setMaxRedirects(int max)
sets the max_redirects option
QoreHttpClientObject::setEncoding
DLLEXPORT void setEncoding(const QoreEncoding *qe)
sets the default encoding for the object
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275
QoreHttpClientObject::getEncoding
DLLEXPORT const QoreEncoding * getEncoding() const
returns the default encoding for the object
QoreHttpClientObject::disconnect
DLLEXPORT void disconnect()
disconnects from the remote server
QoreObject
the implementation of Qore&#39;s object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:60
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
QoreHttpClientObject
provides a way to communicate with HTTP servers using Qore data structures
Definition: QoreHttpClientObject.h:51
QoreHttpClientObject::setProxySecure
DLLEXPORT void setProxySecure(bool is_secure)
sets the SSL flag for use in the next connection to the proxy
QoreHttpClientObject::getAssumedEncoding
DLLEXPORT QoreStringNode * getAssumedEncoding() const
gets the assumed encoding
InputStream
Interface for private data of input streams.
Definition: InputStream.h:44
QoreHttpClientObject::getProxyURL
DLLEXPORT QoreStringNode * getProxyURL()
returns the proxy connection parameters as a URL (or 0 if there is none), caller owns the reference c...
QoreHttpClientObject::setNoDelay
DLLEXPORT int setNoDelay(bool nodelay)
sets the TCP_NODELAY flag on the object
int64
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
QoreHttpClientObject::isHTTP11
DLLEXPORT bool isHTTP11() const
returns true if HTTP 1.1 protocol compliance has been set
QoreHttpClientObject::getDefaultPath
DLLEXPORT const char * getDefaultPath() const
returns the default path or 0 if none is set
QoreHttpClientObject::isConnected
DLLEXPORT bool isConnected() const
returns the connection status of the object
QoreHttpClientObject::getRedirectPassthru
DLLEXPORT bool getRedirectPassthru() const
returns the current redirect_passthru status
ResolvedCallReferenceNode
base class for resolved call references
Definition: CallReferenceNode.h:109
QoreHttpClientObject::setSecure
DLLEXPORT void setSecure(bool is_secure)
sets the SSL flag for use in the next connection
common.h
QoreHttpClientObject::clearUserPassword
DLLEXPORT void clearUserPassword()
clears the username and password for the connection
QoreHttpClientObject::setEventQueue
DLLEXPORT void setEventQueue(Queue *cbq, ExceptionSink *xsink)
sets the event queue, must be already referenced before call
QoreHttpClientObject::getErrorPassthru
DLLEXPORT bool getErrorPassthru() const
returns the current error_passthru status
QoreHttpClientObject::setProxyUserPassword
DLLEXPORT void setProxyUserPassword(const char *user, const char *pass)
sets the username and password for the proxy connection
QoreHttpClientObject::getHostHeaderValue
DLLEXPORT QoreStringNode * getHostHeaderValue() const
returns the Host header value
QoreHttpClientObject::send
DLLEXPORT QoreHashNode * send(const char *meth, const char *path, const QoreHashNode *headers, const void *data, unsigned size, bool getbody, QoreHashNode *info, ExceptionSink *xsink)
sends a message to the remote server and returns the entire response as a hash, caller owns the QoreH...
QoreHttpClientObject::setConnectionPath
DLLEXPORT void setConnectionPath(const char *path)
sets or clears the connection path
QoreHttpClientObject::clearProxyURL
DLLEXPORT void clearProxyURL()
clears the proxy URL
QoreHttpClientObject::getMaxRedirects
DLLEXPORT int getMaxRedirects() const
returns the value of the max_redirects option