Qore Programming Language Reference Manual 2.0.0
|
The HTTPClient class can be used to communicate with HTTP servers with and without TLS/SSL encryption. More...
#include <QC_HTTPClient.dox.h>
Public Member Methods | |
nothing | addDefaultHeaders (hash< auto > hdr) |
Sets headers to send by default with every outgoing request. | |
clearPersistent () | |
Decrements the persistent connection count and clears the persistent connection flag when it reaches zero. | |
nothing | clearProxyURL () |
Clears the new proxy URL value for the next connection. | |
nothing | clearProxyUserPassword () |
Clears the username and password for the next proxy connection. | |
clearStats () | |
Clears performance statistics. | |
nothing | clearUserPassword () |
Clears the username and password for the connection. | |
nothing | clearWarningQueue () |
Removes any warning Queue object from the Socket. | |
nothing | connect () |
Connects to the remote socket; SSL/TLS negotiation is performed if required. | |
constructor (hash< auto > opts) | |
Creates the HTTPClient object based on the option parameter passed. | |
constructor () | |
Creates the HTTPClient object. | |
copy () | |
Copying objects of this class is not supported, an exception will be thrown. | |
destructor () | |
Destroys the HTTPClient object and closes any open connections. | |
nothing | disconnect () |
Disconnects from the remote socket if a connection is established (otherwise does nothing) | |
__7_ string | get (string path, __7_ hash< auto > headers, __7_ reference< hash< auto > > info) |
Sends an HTTP GET request and returns the message body received as a string or NOTHING if no message body is received. | |
string | getAssumedEncoding () |
returns the assumed character encoding for messages from the HTTP server without any charset indicator | |
int | getConnectTimeout () |
Returns the connect timeout as an integer in milliseconds. | |
__7_ string | getConnectionPath () |
Returns the current connection path set in the URL. | |
hash< string, string > | getDefaultHeaders () |
Returns a hash of default headers to be sent with every outgoing request. | |
string | getDefaultPath () |
Returns the default path used by the object if no path is set in the URL. | |
string | getEncoding () |
Returns the character encoding used for the object. | |
bool | getEncodingPassthru () |
get the encoding passthru status | |
bool | getErrorPassthru () |
get the error passthru status | |
string | getHTTPVersion () |
Returns the HTTP protocol version string used in outgoing messages. | |
string | getHostHeaderValue () |
returns the Host header value for this object | |
hash< auto > | getHttpConfig () |
Returns the configuration of the HTTP client. | |
int | getMaxRedirects () |
Returns the current max_redirects value for the object (the maximum number of HTTP redirects that will be processed before an exception is raised) | |
bool | getNoDelay () |
Returns the TCP_NODELAY setting for the HTTPClient object. | |
__7_ string | getPassword () |
Returns any password set for the connection. | |
int | getPersistentCount () |
Returns the persistent connection count. | |
bool | getPreEncodedUrls () |
get the pre-encoded URL flag | |
__7_ string | getProxyPassword () |
Returns any password set for the proxy connection, if any. | |
__7_ string | getProxyURL () |
Returns the current proxy URL as a string or NOTHING if no proxy URL is set. | |
__7_ string | getProxyUsername () |
Returns any username set for the proxy connection, if any. | |
bool | getRedirectPassthru () |
get the redirect passthru status | |
__7_ string | getSafeProxyURL () |
Returns the current proxy URL without the password field. | |
__7_ string | getSafeURL () |
Returns the current URL without the password field. | |
int | getTimeout () |
Returns the default I/O timeout as an integer in milliseconds. | |
__7_ string | getURL () |
Returns the current URL. | |
hash< auto > | getUsageInfo () |
Returns performance statistics for the socket. | |
__7_ string | getUsername () |
Returns any username set for the connection. | |
hash< auto > | head (string path, __7_ hash< auto > headers, __7_ reference< hash< auto > > info) |
Sends an HTTP HEAD request and returns as hash of the headers received. | |
bool | isConnected () |
Returns True or False giving the current connection state. | |
bool | isPersistent () |
Returns True if the persistent flag is set. | |
bool | isProxySecure () |
Returns the SSL/TLS flag for the next proxy connection. | |
bool | isSecure () |
Returns True if the current connection is encrypted, False if not. | |
__7_ string | post (string path, string body, __7_ hash< auto > headers, __7_ reference< hash< auto > > info) |
Sends an HTTP POST request with a message body and returns the message body received as a string or NOTHING if no message body is received. | |
__7_ string | post (string path, __7_ binary body, __7_ hash< auto > headers, __7_ reference< hash< auto > > info) |
Sends an HTTP POST request with a message body and returns the message body received as a string or NOTHING if no message body is received. | |
hash< auto > | send (string body, string method, __7_ string path, __7_ hash< auto > headers, softbool getbody=False, __7_ reference< hash< auto > > info) |
Sends an HTTP request with the specified method and optional message body. | |
hash< auto > | send (__7_ binary body, string method, __7_ string path, __7_ hash< auto > headers, softbool getbody=False, __7_ reference< hash< auto > > info) |
Sends an HTTP request with the specified method and optional message body and returns headers and any body received as a response in a hash format. | |
nothing | send (Qore::OutputStream os, __7_ data body, string method, __7_ string path, __7_ hash< auto > headers, timeout timeout_ms=0, softbool getbody=False, __7_ reference< hash< auto > > info, __7_ code rcb) |
Sends an HTTP request with the specified method and optional message body; headers are returned through an optional receive callback and any body received is written to the OutputStream. | |
nothing | sendChunked (Qore::OutputStream os, Qore::InputStream is, string method, int max_chunk_size=4096, __7_ string path, __7_ hash< auto > headers, timeout timeout_ms=0, softbool getbody=False, __7_ reference< hash< auto > > info, __7_ code rcb, __7_ code tcb) |
Sends a chunked HTTP request with the specified method and message body; headers are returned through an optional receive callback and any body received is written to the OutputStream. | |
nothing | sendWithCallbacks (code scb, code rcb, string method, __7_ string path, __7_ hash< auto > headers, timeout timeout_ms=0, softbool getbody=False, __7_ reference< hash< auto > > info) |
Sends an HTTP request with the specified method and chunked message body as given by a send callback; headers and any body received are returned through a receive callback. | |
nothing | sendWithRecvCallback (code rcb, string body, string method, __7_ string path, __7_ hash< auto > headers, timeout timeout_ms=0, softbool getbody=False, __7_ reference< hash< auto > > info) |
Sends an HTTP request with the specified method and optional message body; headers and any body received are returned through a receive callback. | |
nothing | sendWithRecvCallback (code rcb, __7_ binary body, string method, __7_ string path, __7_ hash< auto > headers, timeout timeout_ms=0, softbool getbody=False, __7_ reference< hash< auto > > info) |
Sends an HTTP request with the specified method and optional message body; headers and any body received are returned through a receive callback. | |
hash< auto > | sendWithSendCallback (code scb, string method, __7_ string path, __7_ hash< auto > headers, timeout timeout_ms=0, softbool getbody=False, __7_ reference< hash > info) |
Sends an HTTP request with the specified method and chunked message body as given by a send callback and returns headers and any body received as a response in a hash format. | |
setAssumedEncoding (__7_ string encoding) | |
sets the assumed character encoding for messages from the HTTP server without any charset indicator | |
nothing | setConnectTimeout (timeout timeout_ms=-1) |
Sets the connect timeout in milliseconds. | |
setConnectionPath (__7_ string uri_path) | |
Overrides any connection path set in the URL. | |
nothing | setDefaultPath (__7_ string path) |
Sets the default path used by the object if no path is set in the URL. | |
nothing | setEncoding (string encoding) |
Sets the string encoding for the object; any strings deserialized with this object will be tagged with this character encoding. | |
bool | setEncodingPassthru (bool set=True) |
set the encoding passthru status | |
bool | setErrorPassthru (bool set=True) |
set the error passthru status | |
nothing | setEventQueue () |
Clears any Queue object that may be set on the HTTPClient object so that I/O events are no longer captured on the object. | |
nothing | setEventQueue (Qore::Thread::Queue queue, auto arg, __7_ bool with_data) |
Sets a Queue object to receive HTTPClient and Socket events. | |
nothing | setHTTPVersion (string ver) |
Sets the HTTP protocol version string for headers in outgoing messages, allowed values are "1.0" and "1.1". | |
nothing | setMaxRedirects (softint mr=0) |
Updates the setting for the max_redirects value for the object (maximum number of HTTP redirects that will be processed before an exception is raised) | |
int | setNoDelay (softbool b=True) |
Sets the TCP_NODELAY setting for the object. | |
setPersistent () | |
temporarily disables implicit reconnections; must be called when the server is already connected | |
bool | setPreEncodedUrls (bool set=True) |
set the pre-encoded URL flag | |
nothing | setProxySecure (softbool b=True) |
Sets the SSL/TLS flag for the next connection to the proxy. | |
nothing | setProxyURL () |
Clears the new proxy URL value for the next connection. | |
nothing | setProxyURL (string url) |
Sets a new proxy URL value for the next connection. | |
nothing | setProxyUserPassword (string user, string pass) |
Sets the username and password for the connection to the proxy; call after HTTPClient::setProxyURL() | |
nothing | setProxyUserPassword () |
Clears the username and password for the next proxy connection. | |
bool | setRedirectPassthru (bool set=True) |
set the redirect passthru status | |
nothing | setSecure (softbool secure=True) |
Sets the object to make a secure SSL/TLS connection on the next connect if the passed argument is True, or an unencrypted cleartext connection if it is False. | |
nothing | setTimeout (timeout timeout_ms=0) |
Sets the default I/O timeout value in milliseconds. | |
setURL (string url) | |
Sets a new URL value for the next connection. | |
nothing | setUserPassword (string user, string pass) |
Sets the username and password for the connection; call after HTTPClient::setURL() | |
nothing | setUserPassword () |
Clears the username and password for the connection. | |
nothing | setWarningQueue (int warning_ms, int warning_bs, Queue queue, auto arg, timeout min_ms=1s) |
Sets a Queue object to receive socket warnings. | |
AbstractPollOperation | startPollConnect () |
Returns an AbstractPollOperation object to make a non-blocking HTTP connection. | |
AbstractPollOperation | startPollSendRecv (string method, __7_ string path, string body, __7_ hash< auto > headers) |
Returns an AbstractPollOperation object to send a message and receive the response. | |
AbstractPollOperation | startPollSendRecv (string method, __7_ string path, __7_ binary body, __7_ hash< auto > headers) |
Returns an AbstractPollOperation object to send a message and receive the response. | |
Public Member Methods inherited from Qore::Socket | |
Socket | accept () |
Accepts connections on a listening socket. | |
__7_ Socket | accept (timeout timeout_ms) |
Accepts connections on a listening socket (see Socket::listen()) accepting a timeout value with a millisecond resolution. | |
acceptAllCertificates (bool accept_all=True) | |
with peer verification enabled, all certificates are accepted regardless of the validity of the Certificate Authority | |
Socket | acceptSSL () |
Accepts connections on a listening socket and attempts to negotiate a TLS/SSL connection. | |
__7_ Socket | acceptSSL (timeout timeout_ms) |
Accepts connections on a listening socket and attempts to negotiate a TLS/SSL connection accepting a timeout value with a millisecond resolution. | |
int | bind (string str, softbool reuseaddr=False) |
Opens and binds the socket to a port, interface and port (if the bind_to string has a format "host:port"), or UNIX domain socket file. | |
int | bind (int port, softbool reuseaddr=False) |
Opens and binds the socket to an INET port on all interfaces. | |
nothing | bindINET (__7_ string iface, __7_ softstring service, softbool reuseaddr=False, softint family=AF_UNSPEC, softint socktype=SOCK_STREAM, softint protocol=0) |
Opens and binds the socket to the given IPv4 or IPv6 interface (or if no interface is given, then to all interfaces on the local system) and port (the port number will be derived from the service name if a numeric port number is not given) | |
nothing | bindUNIX (string path, softint socktype=SOCK_STREAM, softint protocol=0) |
Opens and binds the socket to the given UNIX domain socket file as given by the filename argument. If any errors occur, an exception is thrown. | |
bool | captureRemoteCertificates (bool set=True) |
Sets the flag for capturing remote X.509 certificates; by default no capture of remote certificates is performed. | |
clearStats () | |
Clears performance statistics. | |
nothing | clearWarningQueue () |
Removes any warning Queue object from the Socket. | |
int | close () |
Closes an open socket. | |
nothing | connect (string target, timeout timeout_ms=-1) |
Connects to a remote port (if the string has a format "host:port") or UNIX domain socket file. | |
nothing | connectINET (string host, softstring service, timeout timeout_ms=-1, softint family=AF_UNSPEC, softint socktype=SOCK_STREAM, softint protocol=0) |
Connects to the given host and port with an optional timeout value with a millisecond resolution. | |
nothing | connectINETSSL (string host, softstring service, timeout timeout_ms=-1, softint family=AF_UNSPEC, softint socktype=SOCK_STREAM, softint protocol=0) |
Connects to the given host and port and attempts to establish a TLS/SSL connection; accepts an optional timeout value with a millisecond resolution. | |
nothing | connectSSL (string target, timeout timeout_ms=-1) |
Connects to a remote socket and attempts to establish a TLS/SSL connection; accepts an optional timeout value with a millisecond resolution. | |
nothing | connectUNIX (string path, softint socktype=SOCK_STREAM, softint protocol=0) |
Connects to a UNIX domain socket file. | |
nothing | connectUNIXSSL (string path, softint socktype=SOCK_STREAM, softint protocol=0) |
Connects to the given UNIX domain socket file and attempts to establish a TLS/SSL connection. | |
constructor () | |
Creates the socket object. | |
copy () | |
Creates a new Socket object, not based on the source being copied. | |
destructor () | |
Deletes the object. | |
bool | getAcceptAllCertificates () |
returns the current value of the "accept all certificates" flag | |
string | getCharset () |
Returns the character encoding for the socket. | |
int | getConnectionId () |
Returns an integer connection ID that is incremented every time the socket is disconnected. | |
string | getEncoding () |
Returns the character encoding for the socket. | |
bool | getNoDelay () |
Returns the TCP_NODELAY setting for the socket. | |
hash< auto > | getPeerInfo (bool host_lookup=True) |
Returns a hash of information about the remote end for connected sockets. | |
int | getPort () |
Returns the port number of the socket for INET sockets. | |
int | getRecvTimeout () |
Returns the receive timeout socket option value as an integer in milliseconds. | |
__7_ SSLCertificate | getRemoteCertificate () |
Returns any remote certificate captured or NOTHING if there is none. | |
__7_ string | getSSLCipherName () |
Returns the name of the cipher for an encrypted connection or NOTHING if a secure connection has not been established. | |
__7_ string | getSSLCipherVersion () |
Returns the version string of the cipher for an encrypted connection or NOTHING if a secure connection has not been established. | |
int | getSendTimeout () |
Returns the send timeout socket option value as an integer in milliseconds. | |
int | getSocket () |
Returns the socket file descriptor number. | |
hash< auto > | getSocketInfo (bool host_lookup=True) |
Returns information about the local socket as a hash. | |
int | getSslVerifyMode () |
returns the current SSL verification mode | |
hash< auto > | getUsageInfo () |
Returns performance statistics for the socket. | |
bool | isDataAvailable (timeout timeout_ms=0) |
Returns True or False depending on whether there is data to be read on the socket. | |
bool | isOpen () |
Returns True if the socket is open. | |
bool | isSecure () |
Returns True if the connection is a secure TLS/SSL connection. | |
bool | isWriteFinished (timeout timeout_ms=0) |
Returns True or False depending on whether all the data has been written to the socket. | |
int | listen (int backlog=20) |
Listens for connections on a bound socket; sets the socket in a listening state. | |
bool | pendingHttpChunkedBody () |
returns True if the socket is still connected, and a HTTP header was read indicating chunked transfer encoding, but no chunked body has been read yet | |
hash< auto > | readHTTPChunkedBody (timeout timeout_ms=-1) |
Reads in an HTTP message body sent in chunked transfer encoding and returns it with any footers received as a string in the "body" key of a hash (including footers received) | |
hash< auto > | readHTTPChunkedBodyBinary (timeout timeout_ms=-1) |
Reads in an HTTP message body sent in chunked transfer encoding and returns it with any footers received as a binary object in the "body" key of a hash (including footers received) | |
readHTTPChunkedBodyBinaryWithCallback (code rcb, timeout timeout_ms=-1) | |
Reads in an HTTP message body sent in chunked transfer encoding and returns it with any footers received as a string in the "body" key of a hash (including footers received) | |
hash< auto > | readHTTPChunkedBodyToOutputStream (Qore::OutputStream os, timeout timeout_ms=-1) |
Reads in an HTTP message body sent in chunked transfer encoding, writes it in an OutputStream and returns any footers received. | |
readHTTPChunkedBodyWithCallback (code rcb, timeout timeout_ms=-1) | |
Reads in an HTTP message body sent in chunked transfer encoding and returns it with any footers received as a string in the "body" key of a hash (including footers received) | |
hash< auto > | readHTTPHeader (timeout timeout_ms=-1, __7_ reference< hash< auto > > info) |
Retuns a hash representing the data in the HTTP header read, or, if the data cannot be parsed as an HTTP header, then an exception is thrown, and the data read is returned as a string in the arg key of the exception hash. | |
string | readHTTPHeaderString (timeout timeout_ms=-1) |
Retuns a string representing the data in the HTTP header read (reads until "\r\n\r\n" ) | |
string | recv (softint size=0, timeout timeout_ms=-1) |
Receives data from the socket and returns a string tagged with the Socket's character encoding. | |
binary | recvBinary (softint size=0, timeout timeout_ms=-1) |
Receives data from the socket and returns a binary object. | |
nothing | recvToOutputStream (Qore::OutputStream os, softint size=-1, timeout timeout_ms=-1) |
Receives data from the socket and writes the bytes to an OutputStream. | |
int | recvi1 (timeout timeout_ms=-1) |
Receives a 1-byte signed integer from the socket. | |
int | recvi2 (timeout timeout_ms=-1) |
Receives a 2-byte (16-bit) signed integer in big-endian format (network byte order) from the socket. | |
int | recvi2LSB (timeout timeout_ms=-1) |
Receives a 2-byte (16-bit) signed integer in little-endian format from the socket. | |
int | recvi4 (timeout timeout_ms=-1) |
Receives a 4-byte (32-bit) signed integer in big-endian format (network byte order) from the socket. | |
int | recvi4LSB (timeout timeout_ms=-1) |
Receives a 4-byte (32-bit) signed integer in little-endian format from the socket. | |
int | recvi8 (timeout timeout_ms=-1) |
Receives an 8-byte (64-bit) signed integer in big-endian format (network byte order) from the socket. | |
int | recvi8LSB (timeout timeout_ms=-1) |
Receives an 8-byte (64-bit) signed integer in little-endian format from the socket. | |
int | recvu1 (timeout timeout_ms=-1) |
Receives a 1-byte unsigned integer from the socket. | |
int | recvu2 (timeout timeout_ms=-1) |
Receives a 2-byte (16-bit) unsigned integer in big-endian format (network byte order) from the socket. | |
int | recvu2LSB (timeout timeout_ms=-1) |
Receives a 2-byte (16-bit) unsigned integer in little-endian format from the socket. | |
int | recvu4 (timeout timeout_ms=-1) |
Receives a 4-byte (32-bit) unsigned integer in big-endian format (network byte order) from the socket. | |
int | recvu4LSB (timeout timeout_ms=-1) |
Receives a 4-byte (32-bit) unsigned integer in little-endian format from the socket. | |
int | send (binary bin, timeout timeout_ms=-1) |
Sends binary data over the socket; if any errors occur, an exception is thrown. | |
int | send (string str, timeout timeout_ms=-1) |
Sends string data over the socket; string data is converted to the socket's encoding if necessary; if any errors occur, an exception is thrown. | |
nothing | send2 (binary bin, timeout timeout_ms=-1) |
Sends binary data over the socket; if any errors occur, an exception is thrown. | |
nothing | send2 (string str, timeout timeout_ms=-1) |
Sends string data over the socket; string data is converted to the socket's encoding if necessary; if any errors occur, an exception is thrown. | |
int | sendBinary (string str, timeout timeout_ms=-1) |
Sends string data over the socket without converting the string to the socket's encoding, but instead is sent exactly as-is; if any errors occur, an exception is thrown. | |
int | sendBinary (binary bin, timeout timeout_ms=-1) |
Sends binary data over the socket; if any errors occur, an exception is thrown. | |
nothing | sendBinary2 (string str, timeout timeout_ms=-1) |
Sends string data over the socket without converting the string to the socket's encoding, but instead is sent exactly as-is; if any errors occur, an exception is thrown. | |
nothing | sendBinary2 (binary bin, timeout timeout_ms=-1) |
Sends binary data over the socket; if any errors occur, an exception is thrown. | |
nothing | sendFromInputStream (Qore::InputStream input_stream, softint size=-1, timeout timeout_ms=-1) |
Reads data from an InputStream and sends the bytes over the socket. | |
nothing | sendHTTPChunkedBodyFromInputStream (Qore::InputStream input_stream, int max_chunk_size=4096, timeout timeout_ms=-1, __7_ code tcb) |
Sends an HTTP message body in chunked transfer encoding. | |
nothing | sendHTTPChunkedBodyTrailer (__7_ hash< auto > trailer, timeout timeout_ms=-1) |
Sends the trialer of an HTTP message body in chunked transfer encoding. | |
nothing | sendHTTPMessage (string method, string path, string http_version, hash< auto > headers, string body, __7_ reference< hash > info, timeout timeout_ms=-1) |
Sends an HTTP message with a method and user-defined headers given as a hash and an optional message body. | |
nothing | sendHTTPMessage (string method, string path, string http_version, hash< auto > headers, __7_ binary body, __7_ reference< hash< auto > > info, timeout timeout_ms=-1) |
Sends an HTTP message with a method and user-defined headers given as a hash and an optional message body. | |
nothing | sendHTTPMessageWithCallback (code scb, string method, string path, string http_version, hash< auto > headers, __7_ reference< hash< auto > > info, timeout timeout_ms=-1) |
Sends an HTTP message with a method and user-defined headers given as a hash and an optional message body. | |
nothing | sendHTTPResponse (softint status_code, string status_desc, string http_version, hash< auto > headers, string body, timeout timeout_ms=-1) |
Sends an HTTP response with user-defined headers given as a hash and an optional message body. | |
nothing | sendHTTPResponse (softint status_code, string status_desc, string http_version, hash< auto > headers, string body, __7_ reference< hash< auto > > info, timeout timeout_ms=-1) |
Sends an HTTP response with user-defined headers given as a hash and an optional message body. | |
nothing | sendHTTPResponse (softint status_code, string status_desc, string http_version, hash< auto > headers, __7_ binary body, timeout timeout_ms=-1) |
Sends an HTTP response with user-defined headers given as a hash and a message body as literal binary data. | |
nothing | sendHTTPResponse (softint status_code, string status_desc, string http_version, hash< auto > headers, __7_ binary body, __7_ reference< hash< auto > > info, timeout timeout_ms=-1) |
Sends an HTTP response with user-defined headers given as a hash and a message body as literal binary data. | |
nothing | sendHTTPResponse (softint status_code, string status_desc, string http_version, hash< auto > headers, Qore::InputStream input_stream, int max_chunk_size=4096, __7_ reference< hash< auto > > info, timeout timeout_ms=-1, __7_ code tcb) |
Sends an HTTP response with user-defined headers and a message body from an input stream in chunked transfer encoding. | |
nothing | sendHTTPResponseWithCallback (code scb, softint status_code, string status_desc, string http_version, hash< auto > headers, timeout timeout_ms=-1) |
Sends an HTTP response with user-defined headers given as a hash and a message body to send with chunked transfer encoding provided by a callback. | |
nothing | sendHTTPResponseWithCallback (code scb, softint status_code, string status_desc, string http_version, hash< auto > headers, __7_ reference< hash< auto > > info, timeout timeout_ms=-1) |
Sends an HTTP response with user-defined headers given as a hash and a message body to send with chunked transfer encoding provided by a callback. | |
int | sendi1 (softint i=0, timeout timeout_ms=-1) |
Sends a 1-byte integer over the socket. | |
int | sendi2 (softint i=0, timeout timeout_ms=-1) |
Sends a 2-byte (16-bit) integer in big-endian format (network byte order) over the socket. | |
int | sendi2LSB (softint i=0, timeout timeout_ms=-1) |
Sends a 2-byte (16-bit) integer in little-endian format over the socket. | |
int | sendi4 (softint i=0, timeout timeout_ms=-1) |
Sends a 4-byte (32-bit) integer in big-endian format (network byte order) over the socket. | |
int | sendi4LSB (softint i=0, timeout timeout_ms=-1) |
Sends a 4-byte (32-bit) integer in little-endian format over the socket. | |
int | sendi8 (softint i=0, timeout timeout_ms=-1) |
Sends an 8-byte (64-bit) integer in big-endian format (network byte order) over the socket. | |
int | sendi8LSB (softint i=0, timeout timeout_ms=-1) |
Sends an 8-byte (64-bit) integer in little-endian format over the socket. | |
nothing | setCertificate (SSLCertificate cert) |
Sets the X.509 certificate to use for negotiating encrypted connections. | |
nothing | setCertificate (string cert_pem) |
Sets the X.509 certificate to use for negotiating encrypted connections from the PEM-encoded string representing the X.509 certificate. | |
nothing | setCertificate (binary cert_der) |
Sets the X.509 certificate to use for negotiating encrypted connections from the DER-encoded binary object representing the X.509 certificate. | |
nothing | setCertificateAndPrivateKey (SSLCertificate cert, SSLPrivateKey key) |
Sets the X.509 certificate and private key in one atomic operation to use for negotiating encrypted connections. | |
nothing | setCharset (string encoding) |
Sets the character encoding for the socket. | |
nothing | setEncoding (string encoding) |
Sets the character encoding for the socket. | |
nothing | setEventQueue () |
Removes any Queue object from the Socket object so that socket events are no longer added to the Queue. | |
nothing | setEventQueue (Qore::Thread::Queue queue, auto arg, __7_ bool with_data) |
Sets a Queue object to receive socket events. | |
int | setNoDelay (bool nd=True) |
Sets the boolean TCP_NODELAY setting for the socket. | |
nothing | setPrivateKey (SSLPrivateKey key) |
Sets the private key to use for negotiating encrypted connections along with the X.509 certificate. | |
nothing | setPrivateKey (string key_pem, __7_ string pass) |
Sets the private key to use for negotiating encrypted connections along with the X.509 certificate from a PEM-encoded string representing the private key and an optional password. | |
nothing | setPrivateKey (binary key_der) |
Sets the private key to use for negotiating encrypted connections along with the X.509 certificate from a DER-encoded binary object representing the private key. | |
int | setRecvTimeout (timeout timeout_ms) |
sets the receive timeout as a socket option | |
int | setSendTimeout (timeout timeout_ms) |
sets the send timeout as a socket option | |
setSslVerifyMode (int mode) | |
sets the SSL verification mode | |
nothing | setWarningQueue (int warning_ms, int warning_bs, Queue queue, auto arg, timeout min_ms=1s) |
Sets a Queue object to receive socket warnings. | |
int | shutdown () |
Ensures that a socket will be closed even if the file descriptor is shared with other processes (for example, after a call to fork()) | |
nothing | shutdownSSL () |
Shuts down the SSL connection on a secure connection. | |
AbstractPollOperation | startPollConnect (string target) |
Returns an AbstractPollOperation object to poll the socket for a standard connection. | |
AbstractPollOperation | startPollConnectSsl (string target) |
Returns an AbstractPollOperation object to poll the socket for an SSL connection. | |
AbstractPollOperation | startPollRecvBinary (int size) |
Returns an AbstractPollOperation object to read data in non-blocking mode. | |
AbstractPollOperation | startPollRecvData () |
Returns an AbstractPollOperation object for receiving data in non-blocking mode. | |
AbstractPollOperation | startPollRecvString (int size) |
Returns an AbstractPollOperation object to read data in non-blocking mode. | |
AbstractPollOperation | startPollRecvUntilBytesBinary (string pattern) |
Returns an AbstractPollOperation object to read data in non-blocking mode. | |
AbstractPollOperation | startPollRecvUntilBytesString (string pattern) |
Returns an AbstractPollOperation object to read data in non-blocking mode. | |
AbstractPollOperation | startPollSend (string data) |
Returns an AbstractPollOperation object to send data in non-blocking mode. | |
AbstractPollOperation | startPollSend (binary data) |
Returns an AbstractPollOperation object to send data in non-blocking mode. | |
AbstractPollOperation | startPollUpgradeClientToSSL () |
Returns an AbstractPollOperation object to upgrade a connected client socket to SSL. | |
nothing | upgradeClientToSSL (timeout timeout_ms=-1) |
Upgrades a client socket connection to a TLS/SSL connection. | |
nothing | upgradeServerToSSL (timeout timeout_ms=-1) |
Upgrades a server socket connection to a TLS/SSL connection. | |
__7_ string | verifyPeerCertificate () |
Returns a string code giving the result of verifying the remote certificate or NOTHING if an encrypted connection is not currently established. | |
Public Member Methods inherited from Qore::AbstractPollableIoObjectBase | |
constructor () | |
Throws an exception; this class is not usable by Qore classes. | |
int | getPollableDescriptor () |
Returns a pollable file / socket / I/O descriptor. | |
Public Member Methods inherited from Qore::AbstractPollableIoObject | |
abstract int | getPollableDescriptor () |
Returns a pollable file / socket / I/O descriptor. | |
Public Member Methods inherited from Qore::Serializable | |
constructor () | |
The constructor does not perform any action; this class is just used to mark a class as serializable by inheriting this class. | |
copy () | |
The copy constructor does not perform any action; this class is just used to mark a class as serializable by inheriting this class. | |
serialize (OutputStream stream, __7_ int flags) | |
converts the object to binary data representing the object | |
binary | serialize (__7_ int flags) |
converts the object to binary data representing the object | |
hash< SerializationInfo > | serializeToData (__7_ int flags) |
converts the object to a serialization hash representing the object | |
Additional Inherited Members | |
Static Public Member Methods inherited from Qore::Socket | |
static list< hash< SocketPollInfo > > | poll (list< hash< SocketPollInfo > > items, timeout timeout_ms) |
polls multiple sockets and returns all sockets with events | |
Static Public Member Methods inherited from Qore::Serializable | |
static auto | deserialize (InputStream stream, __7_ int flags) |
Deserializes data produced with serialize() and returns the value represented by the data. | |
static auto | deserialize (binary bin, __7_ int flags) |
Deserializes data produced with serialize() and returns the value represented by the data. | |
static auto | deserialize (string bin, __7_ int flags) |
Deserializes data produced with serialize() and returns the value represented by the data. | |
static auto | deserialize (hash< SerializationInfo > data, __7_ int flags) |
Deserializes data produced with serializeToData() and returns the value represented by the data. | |
static hash< SerializationInfo > | deserializeToData (InputStream stream, __7_ int flags) |
Deserializes data produced with serialize() and returns the value represented by the data. | |
static hash< SerializationInfo > | deserializeToData (binary bin, __7_ int flags) |
Deserializes data produced with serialize() and returns the value represented by the data. | |
static | serialize (auto val, OutputStream stream, __7_ int flags) |
serializes the data and writes the serialized data to the given output stream | |
static binary | serialize (auto val, __7_ int flags) |
serializes the data and returns the serialized data as a binary object | |
static hash< SerializationInfo > | serializeToData (auto val, __7_ int flags) |
converts the value to a serialization hash representing the value | |
The HTTPClient class can be used to communicate with HTTP servers with and without TLS/SSL encryption.
The HTTPClient class can be used to communicate with HTTP servers using the HTTP or HTTPS (HTTP using an SSL/TLS encrypted connection) protocol.
By default "Connection: Keep-Alive"
is always sent regardless of the HTTP protocol level set for the object, however if a server response contains "Connection: close"
, the connection will be closed as soon as the full response (including any message body if present) has been read.
HTTP redirect responses are supported and can be limited with the max_redirects
constructor hash key or by using the HTTPClient::setMaxRedirects() method. The default maximum number of redirects allowed is 5.
HTTP basic authentication is supported; set the username and password in the URL (ex: "http://username:password@host:port/path"
). To change the URL from the one set by the constructor, call HTTPClient::setURL().
HTTP proxies and basic proxy authentication are supported by setting the proxy constructor hash key to the proxy URL (with a proxy username and password if required) or by calling the HTTPClient::setProxyURL() method.
Objects of this class are thread-safe and support serializing multiple simultaneous requests from many threads. If a request is in progress and another thread attempts to make a request at the same time, the second thread will block until the first is complete. Therefore the total amount of time a thread could wait for a response in a multi-threaded context could be greater than the timeout value (which applies to the maximum time a single internal send() or recv() action can take).
This class understands and automatically decodes "deflate"
, "gzip"
, and "bzip2"
content encodings as well.
The default connect timeout value is 60,000 milliseconds (60 seconds), and the default I/O timeout is 300,000 milliseconds (5 minutes). Note that the timeout value applies to individual internal send() or recv() operations; for this reason for large transfers the overall I/O time could exceed the timeout value.
When an exception is thrown (for example, a response code of < 100
or >= 400
is received from the server), any message body returned will be in the "arg"
key of the exception hash.
This class understands the protocols in the following table.
HTTPClient Class Protocols
Protocol/Scheme | Default Port | SSL? | Description |
http | 80 | No | Unencrypted HTTP protocol |
https | 443 | Yes | HTTP protocol with SSL/TLS encryption |
Whenever using an HTTPClient method where a hash of headers can be passed to the method, some headers are generated by default by the class and can be overridden, and some are cannot be overridden and are ignored if passed by the client. See the following tables for details.
HTTPClient Mandatory Headers
Header | Description |
Content-Length | This header is only sent if a message body is sent, and, if so, the length is calculated automatically. |
HTTPClient Default, but Overridable Headers
Header | Default Value |
Accept | "text/html" |
Content-Type | "text/html" |
User-Agent | "Qore-HTTP-Client/0.8.8" |
Connection | "Keep-Alive" |
Accept-Encoding | "gzip,deflate,bzip2" |
Note that if the Content-Type
header is sent without a ";charset=xxx"
or ";boundary=xxxx"
specification, and a string is used as the message body for the request and the string does not have ISO-8859-1
encoding, a ";charset=xxx"
string will be appended to the Content-Type
header to ensure that the message is received and processed correctly on the remote end. In all other cases the caller is responsible for correctly setting the Content-Type
header including any necessary ":charset=xxx"
specification.
This class supports posting network events to a Queue. See I/O Event Handling for more information.
The events raised by this object are listed in the following table: HTTPClient Events
Name | Description |
EVENT_HTTP_CONTENT_LENGTH | Raised when the HTTP "Content-Length" header is received. |
EVENT_HTTP_CHUNKED_START | Raised when HTTP chunked data is about to be received. |
EVENT_HTTP_CHUNKED_END | Raised when all HTTP chunked data has been received. |
EVENT_HTTP_REDIRECT | Raised when an HTTP redirect message is received. |
EVENT_HTTP_SEND_MESSAGE | Raised when an HTTP message is sent. |
EVENT_HTTP_MESSAGE_RECEIVED | Raised when an HTTP message is received. |
EVENT_HTTP_FOOTERS_RECEIVED | Raised when HTTP footers are received. |
EVENT_HTTP_CHUNKED_DATA_RECEIVED | Raised when a block of HTTP chunked data is received. |
EVENT_HTTP_CHUNK_SIZE | Raised when the next chunk size for HTTP chunked data is known. |
The Qore HTTPClient class allows GET
requests to be made with a message body, however please note that this is a bad practice according to HTTP 1.1 RFCs; specifically:
if the request method does not include defined semantics for an entity-body, then the message-body SHOULD be ignored when handling the request.
A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.
Therefore we can conclude that GET
methods do not define any semantics for message bodies sent with the request, therefore message bodies included with GET
requests SHOULD
be ignored according to the HTTP 1.1 spec, therefore it's recommended not to send a message body with a GET
request if standards compliance and compatibility are goals.
scheme://socket=
url_encoded_path/path
, where url_encoded_path is a path with URL-encoding as performed by encode_url(string, True); for example: "http://socket=%2ftmp%socket-dir%2fsocket-file-1/url/path"
; this allows a filesystem path to be used in the host portion of the URL and for the URL to include a URL path as well.ISO-8859-1
(LATIN-1
) encoding, but in practice for maximum compatibility US-ASCII
should be used with any non-ASCII characters encoded with MIME encoded-word format according to RFC 2047. This class currently only performs character encoding conversion on strings used as the message body.UTF-8
); this class does not include a ";charset="
specification in the "Content-Type"
header when sending binary message bodies.";charset=xxx"
to HTTP messages with a non-ISO-8859-1 string message body Sets headers to send by default with every outgoing request.
hdr | headers to send by default with every outgoing request |
Qore::HTTPClient::clearPersistent | ( | ) |
Decrements the persistent connection count and clears the persistent connection flag when it reaches zero.
When the persistent connection flag is cleared, implicit reconnections are reenabled.
Calls to this method when the persistent connection count is already zero are ignored.
nothing Qore::HTTPClient::clearProxyURL | ( | ) |
Clears the new proxy URL value for the next connection.
nothing Qore::HTTPClient::clearProxyUserPassword | ( | ) |
Clears the username and password for the next proxy connection.
Call this method after calling HTTPClient::setProxyURL() to clear any proxy authentication information present in the URL used in HTTPClient::setProxyURL()
Qore::HTTPClient::clearStats | ( | ) |
Clears performance statistics.
nothing Qore::HTTPClient::clearUserPassword | ( | ) |
Clears the username and password for the connection.
Call this method after calling HTTPClient::setURL() to clear any authentication information present in the URL used in HTTPClient::setURL()
nothing Qore::HTTPClient::clearWarningQueue | ( | ) |
Removes any warning Queue object from the Socket.
nothing Qore::HTTPClient::connect | ( | ) |
Connects to the remote socket; SSL/TLS negotiation is performed if required.
If the protocol indicates that a secure connection should be established (or HTTPClient::setSecure() was called previsouly), SSL/TLS negotiation will be attempted.
If the TCP_NODELAY
flag has been set (see HTTPClient::setNoDelay()), then after a successful connection to the remote socket, this option will be set on the socket. If an error occurs setting the TCP_NODELAY
option, the internal flag is set to false (use HTTPClient::getNoDelay() to check the flag's state) and the error code can be retrieved with errno().
Qore::HTTPClient::constructor | ( | ) |
Creates the HTTPClient object.
Creates the HTTPClient object based on the option parameter passed.
To connect, call any method that requires a connection and an implicit connection is established, or call HTTPClient::connect().
opts | sets options and changes default behaviour for the object, etc; key names are case-sensitive and therefore must all be in lower-case:
|
HTTP-CLIENT-OPTION-ERROR | invalid or unknown option passed in option hash |
HTTP-CLIENT-URL-ERROR | invalid URL string |
HTTP-CLIENT-UNKNOWN-PROTOCOL | unknown protocol passed in URL |
ILLEGAL-FILESYSTEM-ACCESS | if the calling context is restricted with the Qore::PO_NO_FILESYSTEM sandboxing restriction and one of the following options is used: ssl_cert_path or ssl_key_path |
scheme://socket=
url_encoded_path/path
, where url_encoded_path is a path with URL-encoding as performed by encode_url(string, True); for example: "http://socket=%2ftmp%socket-dir%2fsocket-file-1/url/path"
; this allows a filesystem path to be used in the host portion of the URL and for the URL to include a URL path as well.ssl_cert_path
or ssl_key_path
options are usedssl_cert_path
or ssl_key_path
ssl_cert_path
ssl_key_path
ssl_key_password
ssl_verify_cert
encoding_passthru
error_passthru
redirect_passthru
assume_encoding
encoding
headers
ssl_cert_data
ssl_key_data
pre_encoded_urls
encode_chars
username
password
Qore::HTTPClient::copy | ( | ) |
Copying objects of this class is not supported, an exception will be thrown.
HTTPCLIENT-COPY-ERROR | copying HTTPClient objects is not yet supported |
Qore::HTTPClient::destructor | ( | ) |
Destroys the HTTPClient object and closes any open connections.
nothing Qore::HTTPClient::disconnect | ( | ) |
Disconnects from the remote socket if a connection is established (otherwise does nothing)
This method also sets the persistent connection count to zero
__7_ string Qore::HTTPClient::get | ( | string | path, |
__7_ hash< auto > | headers, | ||
__7_ reference< hash< auto > > | info | ||
) |
Sends an HTTP GET
request and returns the message body received as a string or NOTHING if no message body is received.
In order to get the headers and the body, use the HTTPClient::send() method instead (although note that sending an HTTP message bosdy with a GET
request is not standards compliant; see HTTP GET Requests With a Message Body for more information).
If no connection has already been established, an internal call to HTTPClient::connect() will be made before sending the request.
If any content encoding is used for the message body in the reply, the content is decoded and returned as a string; if the content encoding uses an unknown method, then an exception is thrown.
path | the path for the message (i.e. "/path/resource?method¶m=value" ) |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
info | an optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request; this hash contains the following keys:
|
HTTP-CLIENT-REDIRECT-ERROR | invalid redirect location given by remote |
HTTP-CLIENT-MAXIMUM-REDIRECTS-EXCEEDED | maximum redirect count exceeded |
HTTP-CLIENT-RECEIVE-ERROR | unknown content encoding received or status error communicating with HTTP server (status code < 100 or > 299); in case of a status error the "arg" key of the exception hash will be set to a hash equal to the normal return value of this method including a "status_code" key (giving the status code) and a "body" key (giving the message body returned by the server); note that this error is not raised for HTTP status codes indicating an error if the error_passthru option is set to True; see the error_passthru option in HTTPClient::constructor() |
SOCKET-SEND-ERROR | There was an error sending the data |
SOCKET-CLOSED | The remote end closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | Data transmission or reception for a single send() or recv() action exceeded the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | Invalid HTTP data was received |
response-headers-raw
info key string Qore::HTTPClient::getAssumedEncoding | ( | ) |
returns the assumed character encoding for messages from the HTTP server without any charset indicator
"ISO-8859-1"
Returns the current connection path set in the URL.
int Qore::HTTPClient::getConnectTimeout | ( | ) |
Returns the connect timeout as an integer in milliseconds.
Returns a hash of default headers to be sent with every outgoing request.
string Qore::HTTPClient::getDefaultPath | ( | ) |
Returns the default path used by the object if no path is set in the URL.
string Qore::HTTPClient::getEncoding | ( | ) |
Returns the character encoding used for the object.
bool Qore::HTTPClient::getEncodingPassthru | ( | ) |
bool Qore::HTTPClient::getErrorPassthru | ( | ) |
get the error passthru status
error_passthru
valueIf True then HTTP status codes indicating errors will not cause an HTTP-CLIENT-RECEIVE-ERROR
exception to be raised, rather such responses will be passed through to the caller like any other response.
string Qore::HTTPClient::getHostHeaderValue | ( | ) |
returns the Host
header value for this object
Host
header value for this objectReturns the configuration of the HTTP client.
string Qore::HTTPClient::getHTTPVersion | ( | ) |
Returns the HTTP protocol version string used in outgoing messages.
int Qore::HTTPClient::getMaxRedirects | ( | ) |
Returns the current max_redirects
value for the object (the maximum number of HTTP redirects that will be processed before an exception is raised)
max_redirects
value for the object (the maximum number of HTTP redirects that will be processed before an exception is raised)bool Qore::HTTPClient::getNoDelay | ( | ) |
Returns the TCP_NODELAY
setting for the HTTPClient object.
Returns any password set for the connection.
int Qore::HTTPClient::getPersistentCount | ( | ) |
bool Qore::HTTPClient::getPreEncodedUrls | ( | ) |
get the pre-encoded URL flag
pre_encoded_urls
valueIf True then all URI paths in URLs are assumed to be already percent encoded; if this flag is set and any unencoded characters are sent in a URL with a new request, an exception is raised.
Returns any password set for the proxy connection, if any.
Returns the current proxy URL as a string or NOTHING if no proxy URL is set.
Returns any username set for the proxy connection, if any.
bool Qore::HTTPClient::getRedirectPassthru | ( | ) |
Returns the current proxy URL without the password field.
int Qore::HTTPClient::getTimeout | ( | ) |
Returns the default I/O timeout as an integer in milliseconds.
Returns the current URL.
Returns performance statistics for the socket.
"bytes_sent"
: an integer giving the total amount of bytes sent"bytes_recv"
: an integer giving the total amount of bytes received"us_sent"
: an integer giving the total number of microseconds spent sending data"us_recv"
: an integer giving the total number of microseconds spent receiving data"arg"
: (only if warning values have been set with HTTPClient::setWarningQueue()) the optional argument for warning hashes"timeout"
: (only if warning values have been set with HTTPClient::setWarningQueue()) the warning timeout in microseconds"min_throughput"
: (only if warning values have been set with HTTPClient::setWarningQueue()) the minimum warning throughput in bytes/secReturns any username set for the connection.
hash< auto > Qore::HTTPClient::head | ( | string | path, |
__7_ hash< auto > | headers, | ||
__7_ reference< hash< auto > > | info | ||
) |
Sends an HTTP HEAD
request and returns as hash of the headers received.
If no connection is established, an internal call to HTTPClient::connect() will be made before sending the message.
path | the path for the message (i.e. "/path/resource?method¶m=value" ) |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
info | an optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request; this hash contains the following keys:
|
HTTP-CLIENT-REDIRECT-ERROR | invalid redirect location given by remote |
HTTP-CLIENT-MAXIMUM-REDIRECTS-EXCEEDED | maximum redirect count exceeded |
HTTP-CLIENT-RECEIVE-ERROR | unknown content encoding received or status error communicating with HTTP server (status code < 100 or > 299); in case of a status error the "arg" key of the exception hash will be set to a hash equal to the normal return value of this method including a "status_code" key (giving the status code) and a "body" key (giving the message body returned by the server); note that this error is not raised for HTTP status codes indicating an error if the error_passthru option is set to True; see the error_passthru option in HTTPClient::constructor() |
SOCKET-SEND-ERROR | There was an error sending the data |
SOCKET-CLOSED | The remote end closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | Data transmission or reception for a single send() or recv() action exceeded the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | Invalid HTTP data was received |
response-headers-raw
info key bool Qore::HTTPClient::isConnected | ( | ) |
bool Qore::HTTPClient::isPersistent | ( | ) |
bool Qore::HTTPClient::isProxySecure | ( | ) |
Returns the SSL/TLS flag for the next proxy connection.
bool Qore::HTTPClient::isSecure | ( | ) |
__7_ string Qore::HTTPClient::post | ( | string | path, |
__7_ binary | body, | ||
__7_ hash< auto > | headers, | ||
__7_ reference< hash< auto > > | info | ||
) |
Sends an HTTP POST
request with a message body and returns the message body received as a string or NOTHING if no message body is received.
In order to get the headers and the body in the response, use the HTTPClient::send() method instead.
If no connection is established, an internal call to HTTPClient::connect() will be made before sending the message.
path | the path for the message (i.e. "/path/resource?method¶m=value" ) |
body | the optional data to use as the message body |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
info | an optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request; this hash contains the following keys:
|
HTTP-CLIENT-REDIRECT-ERROR | invalid redirect location given by remote |
HTTP-CLIENT-MAXIMUM-REDIRECTS-EXCEEDED | maximum redirect count exceeded |
HTTP-CLIENT-RECEIVE-ERROR | unknown content encoding received or status error communicating with HTTP server (status code < 100 or > 299); in case of a status error the "arg" key of the exception hash will be set to a hash equal to the normal return value of this method including a "status_code" key (giving the status code) and a "body" key (giving the message body returned by the server); note that this error is not raised for HTTP status codes indicating an error if the error_passthru option is set to True; see the error_passthru option in HTTPClient::constructor() |
SOCKET-SEND-ERROR | There was an error sending the data |
SOCKET-CLOSED | The remote end closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | Data transmission or reception for a single send() or recv() action exceeded the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | Invalid HTTP data was received |
response-headers-raw
info key __7_ string Qore::HTTPClient::post | ( | string | path, |
string | body, | ||
__7_ hash< auto > | headers, | ||
__7_ reference< hash< auto > > | info | ||
) |
Sends an HTTP POST
request with a message body and returns the message body received as a string or NOTHING if no message body is received.
In order to get the headers and the body in the response, use the HTTPClient::send() method instead.
If no connection is established, an internal call to HTTPClient::connect() will be made before sending the message.
path | the path for the message (i.e. "/path/resource?method¶m=value" ) |
body | the string to use as the message body |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
info | an optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request; this hash contains the following keys:
|
HTTP-CLIENT-REDIRECT-ERROR | invalid redirect location given by remote |
HTTP-CLIENT-MAXIMUM-REDIRECTS-EXCEEDED | maximum redirect count exceeded |
HTTP-CLIENT-RECEIVE-ERROR | unknown content encoding received or status error communicating with HTTP server (status code < 100 or > 299); in case of a status error the "arg" key of the exception hash will be set to a hash equal to the normal return value of this method including a "status_code" key (giving the status code) and a "body" key (giving the message body returned by the server); note that this error is not raised for HTTP status codes indicating an error if the error_passthru option is set to True; see the error_passthru option in HTTPClient::constructor() |
ENCODING-CONVERSION-ERROR | the given string could not be converted to the socket's character encoding |
SOCKET-SEND-ERROR | There was an error sending the data |
SOCKET-CLOSED | The remote end closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | Data transmission or reception for a single send() or recv() action exceeded the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | Invalid HTTP data was received |
response-headers-raw
info key hash< auto > Qore::HTTPClient::send | ( | __7_ binary | body, |
string | method, | ||
__7_ string | path, | ||
__7_ hash< auto > | headers, | ||
softbool | getbody = False , |
||
__7_ reference< hash< auto > > | info | ||
) |
Sends an HTTP request with the specified method and optional message body and returns headers and any body received as a response in a hash format.
If a connection has not already been established, an internal call to HTTPClient::connect() will be made before sending the message
body | The message body to send; pass NOTHING (no value) to send no body |
method | The name of the HTTP method ("GET" , "POST" , "HEAD" , "OPTIONS" , "PUT" , "DELETE" , "TRACE" , "CONNECT" , or "PATCH" ). Additional methods can be added in the constructor with the a additional_methods option. |
path | The path for the message (i.e. "/path/resource?method¶m=value" ) |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
getbody | If this argument is True, then the object will try to receive a message body even if no "Content-Length" header is present in the response. Use this only with broken servers that send message bodies without a "Content-Length" header. |
info | An optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request; this hash contains the following keys:
|
"body"
key and the HTTP status will be assigned to the "status_code"
key.HTTP-CLIENT-METHOD-ERROR | invalid/unknown HTTP method passed |
HTTP-CLIENT-REDIRECT-ERROR | invalid redirect location given by remote |
HTTP-CLIENT-MAXIMUM-REDIRECTS-EXCEEDED | maximum redirect count exceeded |
HTTP-CLIENT-RECEIVE-ERROR | unknown content encoding received or status error communicating with HTTP server (status code < 100 or > 299); in case of a status error the "arg" key of the exception hash will be set to a hash equal to the normal return value of this method including a "status_code" key (giving the status code) and a "body" key (giving the message body returned by the server); note that this error is not raised for HTTP status codes indicating an error if the error_passthru option is set to True; see the error_passthru option in HTTPClient::constructor() |
SOCKET-SEND-ERROR | There was an error sending the data |
SOCKET-CLOSED | The remote end closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | Data transmission or reception for a single send() or recv() action exceeded the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | Invalid HTTP data was received |
URL-ENCODING-ERROR | Thrown if the pre_encoded_urls option is set, and the URL has at least one unencoded character that requires URL percent encoding |
response-headers-raw
info key nothing Qore::HTTPClient::send | ( | Qore::OutputStream | os, |
__7_ data | body, | ||
string | method, | ||
__7_ string | path, | ||
__7_ hash< auto > | headers, | ||
timeout | timeout_ms = 0 , |
||
softbool | getbody = False , |
||
__7_ reference< hash< auto > > | info, | ||
__7_ code | rcb | ||
) |
Sends an HTTP request with the specified method and optional message body; headers are returned through an optional receive callback and any body received is written to the OutputStream.
This method is useful for receiving data in real time; data are sent to the output stream as soon as they are received. If a connection has not already been established, an internal call to HTTPClient::connect() will be made before sending the message
os | The OutputStream to write the response body to |
body | The message body to send; pass NOTHING (no value) to send no body |
method | The name of the HTTP method ("GET" , "POST" , "HEAD" , "OPTIONS" , "PUT" , "DELETE" , "TRACE" , "CONNECT" , or "PATCH" ). Additional methods can be added in the constructor with the a additional_methods option. |
path | The path for the message (i.e. "/path/resource?method¶m=value" ) |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
timeout_ms | the timeout in milliseconds for the socket I/O operations; 0 means use the default timeout value |
getbody | If this argument is True, then the object will try to receive a message body even if no "Content-Length" header is present in the response. Use this only with broken servers that send message bodies without a "Content-Length" header. |
info | An optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request. |
rcb | An optional receive callback for message headers received only; header or trailer data is placed in a hash with the following keys:
|
HTTP-CLIENT-METHOD-ERROR | invalid/unknown HTTP method passed |
HTTP-CLIENT-REDIRECT-ERROR | invalid redirect location given by remote |
HTTP-CLIENT-MAXIMUM-REDIRECTS-EXCEEDED | maximum redirect count exceeded |
HTTP-CLIENT-RECEIVE-ERROR | unknown content encoding received or status error communicating with HTTP server (status code < 100 or > 299); in case of a status error the "arg" key of the exception hash will be set to a hash equal to the normal return value of this method including a "status_code" key (giving the status code) and a "body" key (giving the message body returned by the server); note that this error is not raised for HTTP status codes indicating an error if the error_passthru option is set to True (see the error_passthru option in HTTPClient::constructor()) or if a receive callback is used |
ENCODING-CONVERSION-ERROR | the given string could not be converted to the socket's character encoding |
SOCKET-SEND-ERROR | There was an error sending the data |
SOCKET-CLOSED | The remote end closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | Data transmission or reception for a single send() or recv() action exceeded the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | Invalid HTTP data was received |
URL-ENCODING-ERROR | Thrown if the pre_encoded_urls option is set, and the URL has at least one unencoded character that requires URL percent encoding |
hash< auto > Qore::HTTPClient::send | ( | string | body, |
string | method, | ||
__7_ string | path, | ||
__7_ hash< auto > | headers, | ||
softbool | getbody = False , |
||
__7_ reference< hash< auto > > | info | ||
) |
Sends an HTTP request with the specified method and optional message body.
If a connection has not already been established, an internal call to HTTPClient::connect() will be made before sending the message
body | The message body to send; note that sending an HTTP message bosdy with a GET request is not standards compliant; see HTTP GET Requests With a Message Body for more information |
method | The name of the HTTP method ("GET" , "POST" , "HEAD" , "OPTIONS" , "PUT" , "DELETE" , "TRACE" , "CONNECT" , or "PATCH" ). Additional methods can be added in the constructor with the a additional_methods option. |
path | The path for the message (i.e. "/path/resource?method¶m=value" ) |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
getbody | If this argument is True, then the object will try to receive a message body even if no "Content-Length" header is present in the response. Use this only with broken servers that send message bodies without a "Content-Length" header. |
info | An optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request; this hash contains the following keys:
|
"body"
key and the HTTP status will be assigned to the "status_code"
key.HTTP-CLIENT-METHOD-ERROR | invalid/unknown HTTP method passed |
HTTP-CLIENT-REDIRECT-ERROR | invalid redirect location given by remote |
HTTP-CLIENT-MAXIMUM-REDIRECTS-EXCEEDED | maximum redirect count exceeded |
HTTP-CLIENT-RECEIVE-ERROR | unknown content encoding received or status error communicating with HTTP server (status code < 100 or > 299); in case of a status error the "arg" key of the exception hash will be set to a hash equal to the normal return value of this method including a "status_code" key (giving the status code) and a "body" key (giving the message body returned by the server); note that this error is not raised for HTTP status codes indicating an error if the error_passthru option is set to True; see the error_passthru option in HTTPClient::constructor() |
ENCODING-CONVERSION-ERROR | the given string could not be converted to the socket's character encoding |
SOCKET-SEND-ERROR | There was an error sending the data |
SOCKET-CLOSED | The remote end closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | Data transmission or reception for a single send() or recv() action exceeded the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | Invalid HTTP data was received |
URL-ENCODING-ERROR | Thrown if the pre_encoded_urls option is set, and the URL has at least one unencoded character that requires URL percent encoding |
response-headers-raw
info key nothing Qore::HTTPClient::sendChunked | ( | Qore::OutputStream | os, |
Qore::InputStream | is, | ||
string | method, | ||
int | max_chunk_size = 4096 , |
||
__7_ string | path, | ||
__7_ hash< auto > | headers, | ||
timeout | timeout_ms = 0 , |
||
softbool | getbody = False , |
||
__7_ reference< hash< auto > > | info, | ||
__7_ code | rcb, | ||
__7_ code | tcb | ||
) |
Sends a chunked HTTP request with the specified method and message body; headers are returned through an optional receive callback and any body received is written to the OutputStream.
This method is useful for receiving data in real time; data are sent to the output stream as soon as they are received. If a connection has not already been established, an internal call to HTTPClient::connect() will be made before sending the message
os | The OutputStream to write the response body to |
is | The InputStream to read the request body from; each read will be sent as a separate chunk |
method | The name of the HTTP method ("GET" , "POST" , "HEAD" , "OPTIONS" , "PUT" , "DELETE" , "TRACE" , "CONNECT" , or "PATCH" ). Additional methods can be added in the constructor with the a additional_methods option. |
max_chunk_size | the maximum chunk size as the read block size for the InputStream read block size; the actual size of the data read will determine the size of each HTTP chunk |
path | The path for the message (i.e. "/path/resource?method¶m=value" ) |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
timeout_ms | the timeout in milliseconds for the socket I/O operations; 0 means use the default timeout value |
getbody | If this argument is True, then the object will try to receive a message body even if no "Content-Length" header is present in the response. Use this only with broken servers that send message bodies without a "Content-Length" header. |
info | An optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request. |
tcb | An optional trailer callback for message trailers to write in the outgoing chunked message; the callback takes no arguments and must return either NOTHING or hash giving a hash of trailers for the final chunk |
rcb | An optional receive callback for message headers received only; header or trailer data is placed in a hash with the following keys:
|
ENCODING-CONVERSION-ERROR | the given string could not be converted to the socket's character encoding |
SOCKET-SEND-ERROR | There was an error sending the data |
SOCKET-CLOSED | The remote end closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | Data transmission or reception for a single send() or recv() action exceeded the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | Invalid HTTP data was received |
URL-ENCODING-ERROR | Thrown if the pre_encoded_urls option is set, and the URL has at least one unencoded character that requires URL percent encoding |
nothing Qore::HTTPClient::sendWithCallbacks | ( | code | scb, |
code | rcb, | ||
string | method, | ||
__7_ string | path, | ||
__7_ hash< auto > | headers, | ||
timeout | timeout_ms = 0 , |
||
softbool | getbody = False , |
||
__7_ reference< hash< auto > > | info | ||
) |
Sends an HTTP request with the specified method and chunked message body as given by a send callback; headers and any body received are returned through a receive callback.
This method is useful for sending chunked message data where the response is also sent with chunked transfer encoding; chunks are sent to the receive callback as soon as they are received. If a connection has not already been established, an internal call to HTTPClient::connect() will be made before sending the message
scb | The callback giving the chunked HTTP data to send; this callback must return either a string or a binary value each time it is called to give the chunked data to send; when all data has been sent, then a hash of message trailers can be sent or simply NOTHING which will close the chunked message |
rcb | The receive callback for the data received; first this method is called with a hash of the message headers, and then with any message body; if a chunked HTTP message is received, then the callback is called once for each chunk; when the message has been received, then the receive callback is called with a hash representing any trailer data received in a chunked transfer or NOTHING if the data was received in a normal message body or if there was no trailer data in a chunked transfer. The argument to this callback is always a hash; data calls have the following keys:
|
method | The name of the HTTP method ("GET" , "POST" , "HEAD" , "OPTIONS" , "PUT" , "DELETE" , "TRACE" , "CONNECT" , or "PATCH" ). Additional methods can be added in the constructor with the a additional_methods option. |
path | The path for the message (i.e. "/path/resource?method¶m=value" ) |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
timeout_ms | the timeout in milliseconds for the socket I/O operations; 0 means use the default timeout value |
getbody | If this argument is True, then the object will try to receive a message body even if no "Content-Length" header is present in the response. Use this only with broken servers that send message bodies without a "Content-Length" header. |
info | An optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request; this hash contains the following keys:
|
HTTP-CLIENT-METHOD-ERROR | invalid/unknown HTTP method passed |
HTTP-CLIENT-REDIRECT-ERROR | invalid redirect location given by remote |
HTTP-CLIENT-MAXIMUM-REDIRECTS-EXCEEDED | maximum redirect count exceeded |
HTTP-CLIENT-RECEIVE-ERROR | unknown content encoding received |
ENCODING-CONVERSION-ERROR | the given string could not be converted to the socket's character encoding |
SOCKET-SEND-ERROR | There was an error sending the data |
SOCKET-CLOSED | The remote end closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | Data transmission or reception for a single send() or recv() action exceeded the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | Invalid HTTP data was received |
URL-ENCODING-ERROR | Thrown if the pre_encoded_urls option is set, and the URL has at least one unencoded character that requires URL percent encoding |
"Transfer-Encoding: chunked"
header is automatically set with this method if no "Transfer-Encoding"
header is already presentsend_aborted
flag is set in the argument to rcb response-headers-raw
info key nothing Qore::HTTPClient::sendWithRecvCallback | ( | code | rcb, |
__7_ binary | body, | ||
string | method, | ||
__7_ string | path, | ||
__7_ hash< auto > | headers, | ||
timeout | timeout_ms = 0 , |
||
softbool | getbody = False , |
||
__7_ reference< hash< auto > > | info | ||
) |
Sends an HTTP request with the specified method and optional message body; headers and any body received are returned through a receive callback.
This method is useful for receiving chunked message data in real time; chunks are sent to the receive callback as soon as they are received. If a connection has not already been established, an internal call to HTTPClient::connect() will be made before sending the message
rcb | The receive callback for the data received; first this method is called with a hash of the message headers, and then with any message body; if a chunked HTTP message is received, then the callback is called once for each chunk; when the message has been received, then the receive callback is called with a hash representing any trailer data received in a chunked transfer or NOTHING if the data was received in a normal message body or if there was no trailer data in a chunked transfer. The argument to this callback is always a hash; data calls have the following keys:
|
body | The message body to send; pass NOTHING (no value) to send no body |
method | The name of the HTTP method ("GET" , "POST" , "HEAD" , "OPTIONS" , "PUT" , "DELETE" , "TRACE" , "CONNECT" , or "PATCH" ). Additional methods can be added in the constructor with the a additional_methods option. |
path | The path for the message (i.e. "/path/resource?method¶m=value" ) |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
timeout_ms | the timeout in milliseconds for the socket I/O operations; 0 means use the default timeout value |
getbody | If this argument is True, then the object will try to receive a message body even if no "Content-Length" header is present in the response. Use this only with broken servers that send message bodies without a "Content-Length" header. |
info | An optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request; this hash contains the following keys:
|
HTTP-CLIENT-METHOD-ERROR | invalid/unknown HTTP method passed |
HTTP-CLIENT-REDIRECT-ERROR | invalid redirect location given by remote |
HTTP-CLIENT-MAXIMUM-REDIRECTS-EXCEEDED | maximum redirect count exceeded |
HTTP-CLIENT-RECEIVE-ERROR | unknown content encoding received |
ENCODING-CONVERSION-ERROR | the given string could not be converted to the socket's character encoding |
SOCKET-SEND-ERROR | There was an error sending the data |
SOCKET-CLOSED | The remote end closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | Data transmission or reception for a single send() or recv() action exceeded the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | Invalid HTTP data was received |
URL-ENCODING-ERROR | Thrown if the pre_encoded_urls option is set, and the URL has at least one unencoded character that requires URL percent encoding |
response-headers-raw
info key nothing Qore::HTTPClient::sendWithRecvCallback | ( | code | rcb, |
string | body, | ||
string | method, | ||
__7_ string | path, | ||
__7_ hash< auto > | headers, | ||
timeout | timeout_ms = 0 , |
||
softbool | getbody = False , |
||
__7_ reference< hash< auto > > | info | ||
) |
Sends an HTTP request with the specified method and optional message body; headers and any body received are returned through a receive callback.
This method is useful for receiving chunked message data in real time; chunks are sent to the receive callback as soon as they are received. If a connection has not already been established, an internal call to HTTPClient::connect() will be made before sending the message
rcb | The receive callback for the data received; first this method is called with a hash of the message headers, and then with any message body; if a chunked HTTP message is received, then the callback is called once for each chunk; when the message has been received, then the receive callback is called with a hash representing any trailer data received in a chunked transfer or NOTHING if the data was received in a normal message body or if there was no trailer data in a chunked transfer. The argument to this callback is always a hash; data calls have the following keys:
|
body | The message body to send |
method | The name of the HTTP method ("GET" , "POST" , "HEAD" , "OPTIONS" , "PUT" , "DELETE" , "TRACE" , "CONNECT" , or "PATCH" ). Additional methods can be added in the constructor with the a additional_methods option. |
path | The path for the message (i.e. "/path/resource?method¶m=value" ) |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
timeout_ms | the timeout in milliseconds for the socket I/O operations; 0 means use the default timeout value |
getbody | If this argument is True, then the object will try to receive a message body even if no "Content-Length" header is present in the response. Use this only with broken servers that send message bodies without a "Content-Length" header. |
info | An optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request; this hash contains the following keys:
|
HTTP-CLIENT-METHOD-ERROR | invalid/unknown HTTP method passed |
HTTP-CLIENT-REDIRECT-ERROR | invalid redirect location given by remote |
HTTP-CLIENT-MAXIMUM-REDIRECTS-EXCEEDED | maximum redirect count exceeded |
HTTP-CLIENT-RECEIVE-ERROR | unknown content encoding received |
ENCODING-CONVERSION-ERROR | the given string could not be converted to the socket's character encoding |
SOCKET-SEND-ERROR | There was an error sending the data |
SOCKET-CLOSED | The remote end closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | Data transmission or reception for a single send() or recv() action exceeded the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | Invalid HTTP data was received |
URL-ENCODING-ERROR | Thrown if the pre_encoded_urls option is set, and the URL has at least one unencoded character that requires URL percent encoding |
response-headers-raw
info key hash< auto > Qore::HTTPClient::sendWithSendCallback | ( | code | scb, |
string | method, | ||
__7_ string | path, | ||
__7_ hash< auto > | headers, | ||
timeout | timeout_ms = 0 , |
||
softbool | getbody = False , |
||
__7_ reference< hash > | info | ||
) |
Sends an HTTP request with the specified method and chunked message body as given by a send callback and returns headers and any body received as a response in a hash format.
If a connection has not already been established, an internal call to HTTPClient::connect() will be made before sending the message
scb | The callback giving the chunked HTTP data to send; this callback must return either a string or a binary value each time it is called to give the chunked data to send; when all data has been sent, then a hash of message trailers can be sent or simply NOTHING which will close the chunked message |
method | The name of the HTTP method ("GET" , "POST" , "HEAD" , "OPTIONS" , "PUT" , "DELETE" , "TRACE" , "CONNECT" , or "PATCH" ). Additional methods can be added in the constructor with the a additional_methods option. |
path | The path for the message (i.e. "/path/resource?method¶m=value" ) |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
timeout_ms | the timeout in milliseconds for the socket I/O operations; 0 means use the default timeout value |
getbody | If this argument is True, then the object will try to receive a message body even if no "Content-Length" header is present in the response. Use this only with broken servers that send message bodies without a "Content-Length" header. |
info | An optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request; this hash contains the following keys:
|
"body"
key and the HTTP status will be assigned to the "status_code"
key.HTTP-CLIENT-METHOD-ERROR | invalid/unknown HTTP method passed |
HTTP-CLIENT-REDIRECT-ERROR | invalid redirect location given by remote |
HTTP-CLIENT-MAXIMUM-REDIRECTS-EXCEEDED | maximum redirect count exceeded |
HTTP-CLIENT-RECEIVE-ERROR | unknown content encoding received or status error communicating with HTTP server (status code < 100 or > 299); in case of a status error the "arg" key of the exception hash will be set to a hash equal to the normal return value of this method including a "status_code" key (giving the status code) and a "body" key (giving the message body returned by the server); note that this error is not raised for HTTP status codes indicating an error if the error_passthru option is set to True; see the error_passthru option in HTTPClient::constructor() |
ENCODING-CONVERSION-ERROR | the given string could not be converted to the socket's character encoding |
SOCKET-SEND-ERROR | There was an error sending the data |
SOCKET-CLOSED | The remote end closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | Data transmission or reception for a single send() or recv() action exceeded the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | Invalid HTTP data was received |
URL-ENCODING-ERROR | Thrown if the pre_encoded_urls option is set, and the URL has at least one unencoded character that requires URL percent encoding |
"Transfer-Encoding: chunked"
header is automatically set with this method if no "Transfer-Encoding"
header is already presentresponse-headers-raw
info key sets the assumed character encoding for messages from the HTTP server without any charset indicator
encoding | the encoding to set; if empty or not present, the default "ISO-8859-1" will be set |
Overrides any connection path set in the URL.
Sets the connect timeout in milliseconds.
timeout_ms | the connect timeout in milliseconds; negative numbers mean use the default system connect timeout. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 30s = 30 seconds, etc.) |
Sets the default path used by the object if no path is set in the URL.
path | the default path value to set or if NOTHING then clears the path |
Sets the string encoding for the object; any strings deserialized with this object will be tagged with this character encoding.
encoding | the string encoding for the object; any strings deserialized with this object will be tagged with this character encoding |
set the encoding passthru status
set | if True then message bodies received with known content encodings are not decoded but rather passed through as-is |
encoding_passthru
valueIf True then message bodies received with known content encodings are not decoded but rather passed through as-is
set the error passthru status
set | if True then HTTP status codes indicating errors will not cause an HTTP-CLIENT-RECEIVE-ERROR exception to be raised, rather such responses will be passed through to the caller like any other response |
error_passthru
valueIf True then HTTP status codes indicating errors will not cause an HTTP-CLIENT-RECEIVE-ERROR
exception to be raised, rather such responses will be passed through to the caller like any other response.
nothing Qore::HTTPClient::setEventQueue | ( | ) |
Clears any Queue object that may be set on the HTTPClient object so that I/O events are no longer captured on the object.
nothing Qore::HTTPClient::setEventQueue | ( | Qore::Thread::Queue | queue, |
auto | arg, | ||
__7_ bool | with_data | ||
) |
Sets a Queue object to receive HTTPClient and Socket events.
queue | a Queue object to receive HTTPClient and Socket events; note that the Queue passed cannot have any maximum size set or a QUEUE-ERROR will be thrown |
arg | an argument that will be included in each event hash in the arg key |
with_data | if True, then the actual raw data transferred / received is also included in the events |
QUEUE-ERROR | the Queue passed has a maximum size set |
Sets the HTTP protocol version string for headers in outgoing messages, allowed values are "1.0"
and "1.1".
ver | "1.0" or "1.1" for the HTTP protocol compliance version |
HTTP-VERSION-ERROR | invalid HTTP version passed (allowed values: "1.0" and "1.1") |
Updates the setting for the max_redirects
value for the object (maximum number of HTTP redirects that will be processed before an exception is raised)
mr | the setting for the maximum number of HTTP redirects that will be processed before an exception is raised |
Sets the TCP_NODELAY
setting for the object.
When this setting is True, then data will be immediately sent out over the HTTPClient object's socket, when it is False, then data transmission may be delayed to be packaged with other data for the same target.
Delayed data transmissions may cause problems when the sender immediately closes the socket after sending data; in this case the receiver may not get the data even though the send succeeded.
Note that if no value is given to the method, the argument will be assumed to be True, and output buffering will be turned off for the HTTPClient object.
If the socket is not connected when this call is made, then an internal flag is set and the TCP_NODELAY
option is enabled when the next connection is established. If the socket is connected, then if an error occurs setting the TCP_NODELAY
option on the socket, this method will return a non-zero error code; the actual error can be checked with the errno() function.
b | the TCP_NODELAY setting for the object |
Qore::HTTPClient::setPersistent | ( | ) |
temporarily disables implicit reconnections; must be called when the server is already connected
The persistent flag is automatically reset to False whenever the connection is closed; it must be called manually for every connection to turn off implicit reconnections.
Each call to this method increments the persistent connection flag.
To turn off the persistent flag manually, call one of:
set the pre-encoded URL flag
set | if True then all URI paths in URLs are assumed to be already percent encoded; if this flag is set and any unencoded characters are sent in a URL with a new request, an exception is raised. |
pre_encoded_urls
valueIf True then all URI paths in URLs are assumed to be already percent encoded; if this flag is set and any unencoded characters are sent in a URL with a new request, an exception is raised.
Sets the SSL/TLS flag for the next connection to the proxy.
nothing Qore::HTTPClient::setProxyURL | ( | ) |
Clears the new proxy URL value for the next connection.
This variant of the method is equivalent to HTTPClient::clearProxyURL()
Sets a new proxy URL value for the next connection.
url | the new proxy URL value for the next connection |
HTTP-CLIENT-URL-ERROR | invalid proxy URL string; invalid authorization credentials in proxy URL (username without password or vice-versa) |
HTTP-CLIENT-PROXY-PROTOCOL-ERROR | unknown protocol passed in URL |
scheme://socket=
url_encoded_path/path
, where url_encoded_path is a path with URL-encoding as performed by encode_url(string, True); for example: "http://socket=%2ftmp%socket-dir%2fsocket-file-1/url/path"
; this allows a filesystem path to be used in the host portion of the URL and for the URL to include a URL path as well. nothing Qore::HTTPClient::setProxyUserPassword | ( | ) |
Clears the username and password for the next proxy connection.
Call this method after calling HTTPClient::setProxyURL() to clear any proxy authentication information present in the URL used in HTTPClient::setProxyURL()
This variant of the method is equivalent to HTTPClient::clearProxyUserPassword()
Sets the username and password for the connection to the proxy; call after HTTPClient::setProxyURL()
Call this method after calling HTTPClient::setProxyURL() to set proxy authentication information when not present in the URL used in HTTPClient::setProxyURL()
user | the username to use for proxy authentication in the next HTTP connection |
pass | the password to use for proxy authentication in the next HTTP connection |
set the redirect passthru status
set | if True then redirect messages will be passed to the caller instead of proceessed |
reddirect_passthru
valueIf True then redirect messages will be passed to the callers instead of proceessed
Sets the object to make a secure SSL/TLS connection on the next connect if the passed argument is True, or an unencrypted cleartext connection if it is False.
This method overrides the default behaviour for the protocol set for the object
Note that the behavior of this method when called with no argument changed in version 0.8.0; prior to version 0.8.0 calling this method with no argument would turn off secure mode; the behavior was changed to the current functionality in order to make the usage of this method consistent with other methods of the same name and to make it more logical.
Sets the default I/O timeout value in milliseconds.
timeout_ms | 0 means immediate timeout (when reading will return data only if it is already available), and negative numbers mean never timeout. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.). |
Qore::HTTPClient::setURL | ( | string | url | ) |
Sets a new URL value for the next connection.
To retrieve the current URL value, use the HTTPClient::getURL() method
url | the new URL for the object |
HTTP-CLIENT-URL-ERROR | invalid URL string; invalid authorization credentials in URL (username without password or vice-versa) |
HTTP-CLIENT-UNKNOWN-PROTOCOL | unknown protocol (scheme) passed in URL |
scheme://socket=
url_encoded_path/path
, where url_encoded_path is a path with URL-encoding as performed by encode_url(string, True); for example: "http://socket=%2ftmp%socket-dir%2fsocket-file-1/url/path"
; this allows a filesystem path to be used in the host portion of the URL and for the URL to include a URL path as well. nothing Qore::HTTPClient::setUserPassword | ( | ) |
Clears the username and password for the connection.
Call this method after calling HTTPClient::setURL() to clear any authentication information present in the URL used in HTTPClient::setURL()
This variant of the method is equivalent to HTTPClient::clearUserPassword()
Sets the username and password for the connection; call after HTTPClient::setURL()
Call this method after calling HTTPClient::setURL() to set authentication information when not present in the URL used in HTTPClient::setURL()
user | the username to use for authentication in the next HTTP connection |
pass | the password to use for authentication in the next HTTP connection |
nothing Qore::HTTPClient::setWarningQueue | ( | int | warning_ms, |
int | warning_bs, | ||
Queue | queue, | ||
auto | arg, | ||
timeout | min_ms = 1s |
||
) |
Sets a Queue object to receive socket warnings.
warning_ms | the threshold in milliseconds for individual socket actions (send, receive, connect), if exceeded, a socket warning is placed on the warning queue with the following keys:
|
warning_bs | value in bytes per second; if any call has performance below this threshold, a socket warning is placed on the warning queue with the following keys:
|
queue | the Queue object to receive warning events |
arg | an optional argument to be placed in the "arg" key in each warning hash (could be used to identify the socket for example) |
min_ms | the minimum transfer time with a resolution of milliseconds for a transfer to be eligible for triggering a warning; transfers that take less than this period of time are not eligible for raising a warning |
QUEUE-ERROR | the Queue passed has a maximum size set |
SOCKET-SETWARNINGQUEUE-ERROR | at least one of warning_ms and warning_bs must be > 0 |
AbstractPollOperation Qore::HTTPClient::startPollConnect | ( | ) |
Returns an AbstractPollOperation object to make a non-blocking HTTP connection.
AbstractPollOperation Qore::HTTPClient::startPollSendRecv | ( | string | method, |
__7_ string | path, | ||
__7_ binary | body, | ||
__7_ hash< auto > | headers | ||
) |
Returns an AbstractPollOperation object to send a message and receive the response.
method | The name of the HTTP method ("GET" , "POST" , "HEAD" , "OPTIONS" , "PUT" , "DELETE" , "TRACE" , "CONNECT" , or "PATCH" ). Additional methods can be added in the constructor with the a additional_methods option. |
path | The path for the message (i.e. "/path/resource?method¶m=value" ) |
body | The message body to send; note that sending an HTTP message bosdy with a GET request is not standards compliant; see HTTP GET Requests With a Message Body for more information |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
code:
the HTTP response code returnedinfo:
a hash of information about the request with the following keys:request-uri
: a string giving the request line (ex: PUT / HTTP/1.1
)response-uri
: a string giving the response line (ex: HTTP/1.1 200 OK
)headers-raw
: a hash of raw response headers receivedcharset:
the character encoding used in the responsebody-content-type
]: the Content-Type for the response body (if any)response-headers
: a hash of incoming HTTP headers in the response with keys converted to all lower case for each header in the response message, plus the following Qore-provided keys:http_version:
the HTTP version in the response URIstatus_code:
the HTTP status code of the responsestatus_message:
the HTTP status message of the responserequest-headers
: a hash of headers sent in the requestresponse-body
]: a binary object of any response bodyAbstractPollOperation Qore::HTTPClient::startPollSendRecv | ( | string | method, |
__7_ string | path, | ||
string | body, | ||
__7_ hash< auto > | headers | ||
) |
Returns an AbstractPollOperation object to send a message and receive the response.
method | The name of the HTTP method ("GET" , "POST" , "HEAD" , "OPTIONS" , "PUT" , "DELETE" , "TRACE" , "CONNECT" , or "PATCH" ). Additional methods can be added in the constructor with the a additional_methods option. |
path | The path for the message (i.e. "/path/resource?method¶m=value" ) |
body | The message body to send; note that sending an HTTP message bosdy with a GET request is not standards compliant; see HTTP GET Requests With a Message Body for more information |
headers | An optional hash of headers to include in the message; values are converted to strings; a list is converted to a string of comma-separated values; headers that differ only in case will be overwritten by the last header in the hash with a matching name with a case-insensitive search |
code:
the HTTP response code returnedinfo:
a hash of information about the request with the following keys:request-uri
: a string giving the request line (ex: PUT / HTTP/1.1
)response-uri
: a string giving the response line (ex: HTTP/1.1 200 OK
)headers-raw
: a hash of raw response headers receivedcharset:
the character encoding used in the responsebody-content-type
]: the MIME Content-Type
for the response body (if any)response-headers
: a hash of incoming HTTP headers in the response with keys converted to all lower case for each header in the response message, plus the following Qore-provided keys:http_version:
the HTTP version in the response URIstatus_code:
the HTTP status code of the responsestatus_message:
the HTTP status message of the responserequest-headers
: a hash of headers sent in the requestresponse-body
]: a binary object of any response body