My program doesn't have bugs. It just develops random features.
Legacy:LibHTTP/HttpSock
From Unreal Wiki, The Unreal Engine Documentation Site
Base of LibHTTP this implements the main network methods for connecting
to a webserver and retreiving data from it. Binary data is not supported.
Contents
Constants
- BUFFERSIZE = 2048
- the output buffer size
- HTTP_CONNECT = "CONNECT"
- HTTP_DELETE = "DELETE"
- HTTP_GET = "GET"
- HTTP_HEAD = "HEAD"
- HTTP_OPTIONS = "OPTIONS"
- HTTP_POST = "POST"
- HTTP_PUT = "PUT"
- HTTP_TRACE = "TRACE"
- VERSION = 401
- LibHTTP version number
Properties
- array<string> authBasicLookup
- Base64 encoding lookup table
- bool bAuthTrap
- true if an authentication retry should happen
- bool bIsChunked
- true if the data is chunked (e.g. Transfer-Encoding: chunked )
- int BoundPort
- the port we are connected to
- bool bTempProxyOverride
- will be set to true in case of a ...
- bool bTimeout
- true in case of a connection timeout
- bool bUseTempProxy
- if true use the TempProxy
- int chunkedCounter
- bytes left in the chunk
- HTTPCookies Cookies
- the cookie data instance
- string CRLF
- constant CR LF
- int CurRedir
- current number of redirections
- HTTPState curState
- The current state of the socket
- string EXTENTION
- If you make a custom build of this package, or subclass this class then please change the following constant to countain your "extention" name. This will be used in the UserAgent string. (Change it in the defaultproperties)
- bool FollowingRedir
- true if a redirection should be followed
- class<HttpCookies> HttpCookieClass
- Cookie class to use (if it has not been set)
- HttpLink HttpLink
- handle to the HttpLink
- class<HttpLink> HttpLinkClass
- the link class to use
- string HTTPVER
- The HTTP version to use. Either 1.0 or 1.1 are supported.
- string inBuffer
- i/o buffers
- int LastStatus
- The last returned HTTP status code
- InternetLink.IpAddr LocalLink
- local link address
- string MultiPartBoundary
- Multipart boundary string, used to split fields
- string outBuffer
- i/o buffers
- bool procHeader
- true if headers are being processed
- array<string> RequestData
- the request data
- float RequestDuration
- duration of the last request
- array<string> RequestHeaders
- the request headers
- array<RequestHistoryEntry> RequestHistory
- history with requests for a single request, will contain more then one entry when redirections are followed
- string RequestMethod
- the request method
- HttpResolveCache ResolveCache
- cache object with hostname resolves
- string ResolveHostname
- the hostname being resolved, used to add to the resolve cache
- array<string> ReturnData
- the return data
- array<string> ReturnHeaders
- the return headers
- float StartRequestTime
- start of the request, will be set after the connection was opened and before the actual request will be send
- HttpUtil.xURL TempProxy
- temporary proxy configuration
- int TZoffset
- Timezone Offset, dynamically calculated from the server's time
- HttpUtil Utils
- utility class, used to speed up lookups (optimization)
Authentication
- array<GameInfo.KeyValuePair> AuthInfo
- authentication information
- EAuthMethod AuthMethod
- Authentication method to use when
sUsername
is set. This will automatically be set when aWWW-Authenticate
header is received
- bool bAutoAuthenticate
- If username and password have been set automatically retry the request to authenticate. Note: this can only be done in a second try because the authentication method is required.
Options
- bool bFollowRedirect
- when set to false it won't follow redirects
- bool bProcCookies
- Process incoming cookies, defaults to true
- bool bRfcCompliantRedirect
- responding to HTTP redirect headers is RFC compliant, otherwise it will behave much like some other HTTP clients behave. This means that in case of a 301/302 it will set the request method from POST to GET. This is not the way it should happen according to the standard.
- bool bSendCookies
- Send cookie data when available, defaults to true
- float fConnectTimout
- connection timeout, if the connection couldn't be established within this time limit it will abort the connection and call
OnTimeout()
- int iMaxRedir
- Maximum redirections to follow
- int iVerbose
- log verbosity, you probably want to leave this 0. check the HttpUtil class for various log levels.
Proxy
- bool bUseProxy
- Use a proxy server, this is (and the other proxy settins) a client setting. It's meant for clients to be set when they need to use a proxy.
- int iProxyPort
- The proxy port
- array<GameInfo.KeyValuePair> ProxyAuthInfo
- authentication information
- EAuthMethod ProxyAuthMethod
- Authentication method to use when
sUsername
is set. This will automatically be set when aProxy-Authorisation
header is received
- string sProxyHost
- The hostname of the proxy
- string sProxyPass
- proxy authentication information
- string sProxyUser
- proxy authentication information
URL
- HttpUtil.xURL CurrentURL
- the URL struct for the current request
- string DefaultAccept
- the default value for the Accept header, we only support "text/*"
- int iLocalPort
- the local port, leave zero to use a random port (adviced)
XferMode
- int iMaxBytesPerTick
- maximum number of bytes to download in a single tick
- int iMaxIterationsPerTick
- Maximum iterations per tick in fast transfer mode. This defines the number of download retries (when nothing was received) the code may perform within a single tick. Because the data pending variable is only updated each tick it will remain true until the transfer function returns even tho there is no data pending.
- ETransferMode TransferMode
- Transfer mode to use during downloads
Enums
EAuthMethod
Possible authentication methods, Basic used Base64 encoding to encode the username and password. Digest is more secure.
- AM_None
- AM_Unknown
- AM_Basic
- AM_Digest
ETransferMode
Method used to download the data. TM_Fast
will try to read as much as possible in a single tick, this will have an impact on the game performance during the download. Only use this mode when it's time critical. Use the variables iMaxBytesPerTick
and iMaxIterationsPerTick
to tweak this transfer mode.
- TM_Normal
- TM_Fast
HTTPState
- HTTPState_Resolving
- HTTPState_Connecting
- HTTPState_SendingRequest
- HTTPState_WaitingForResponse
- HTTPState_ReceivingData
- HTTPState_Closed
Structures
RequestHistoryEntry
- string Hostname
- server hostname
- int HTTPresponse
- the HTTP response code received
- string Location
- location, can include GET data
- string Method
- method used in the request
- HttpUtil.xURL URL
- the request URL
Delegates
- bool OnComplete(HttpSock Sender )
- Will be called when the operation was completed successfully.
It won't be called when an time out occured.
- bool OnConnectError(HttpSock Sender )
- Called when Open() fails
- bool OnConnectionTimeout(HttpSock Sender )
- called when the connection has timed out (e.g. open() failed after a set time)
- bool OnError(HttpSock Sender, string ErrorMessage, optional string Param1, optional string Param2 )
- Will be called in case of an internal error.
- OnFollowRedirect(HttpSock Sender, HttpUtil.xURL NewLocation )
- Called before the redirection is followed, return false to prevernt following the redirection
- OnPreConnect(HttpSock Sender )
- Called before the connection is established.
- OnRequestBody(HttpSock Sender )
- Will be called when the request body has to be send. Do note that you are required to set the
Content-Length
header to the total size of the content being send. If you use this delegate to send the request body manually you will have to set the Content-Length header yourself.
- bool OnRequireAuthorization(HttpSock Sender, EAuthMethod method, array<GameInfo.KeyValuePair> info )
- Will be called when authorization is required for the current location.
This will be called directly after receiving the WWW-Authenticate header. So it's best not to stall this call. It's just a notification.
- int OnRequireProxyAuthorization(HttpSock Sender, EAuthMethod method, array<GameInfo.KeyValuePair> info )
- Will be called when authorization is required for the current proxy.
This will be called directly after receiving the Proxy-Authenticate header. So it's best not to stall this call. It's just a notification.
- OnResolved(HttpSock Sender, string hostname, InternetLink.IpAddr Addr )
- Will be called when the host name is resolved.
Return true to continue, or false to abort.
- string OnResolveFailed(HttpSock Sender, string hostname )
- Called when the resolved failed, hostname is the hostname that could not be resolved
- string OnResponseBody(HttpSock Sender, string line )
- Will be called for every response line received (only the body). Return false to stop the default behavior of storing the response body. Use this delegate if you need to have live updates of the content and can not wait until the request is complete.
- string OnReturnCode(HttpSock Sender, int ReturnCode, string ReturnMessage, string HttpVer )
- Will be called when the return code has been received; This is the first function called after the request has been send.
- bool OnSendRequestHeaders(HttpSock Sender )
- This delegate will be send right before the headers are send to the webserver. If you want to change the headers you should do it here.
Warning: becarefull not to change or unset automatically generated headers that are important for this request (like authentication or request body headers)
Functions
- bool Abort( )
- Abort the current request, if possible
- bool AddHeader(string hname, coerce string value, optional bool bNoReplace )
- Add a header, case insensitive. Set bNoReplace to false to not overwrite the old header. Returns true when the header has been set.
- bool CachedResolve(coerce string hostname, optional bool bDontConnect )
- lookup a chached resolve and connect if found
- bool clearFormData( )
- This will clear the POST data. Use this before calling
setFormData
- ClearRequestData(optional bool bDontClearAuth )
- This function will clear the previous request data. You may want to use this when you do a new request with the same socket. Previous set headers won't be unset automatically.
- Closed( )
- connection closed, check for a required redirection
- CloseSocket( )
- destroy the current socket, should only be called in case of a timeout
- bool CreateSocket( )
- create the socket, if required
- int DataSize(array<string> data )
- Return the actual data size of a string array, it appends sizeof(CRLF) for each line. This is used for sending the RequestData.
- string genAuthorization(EAuthMethod method, string Username, string Password, array<GameInfo.KeyValuePair> Info )
- generate the authentication data, depending on the method it will be either a Basic or Digest response
- string genBasicAuthorization(string Username, string Password )
- Generated a basic authentication response
- string genDigestAuthorization(string Username, string Password, array<GameInfo.KeyValuePair> Info )
- generate the Digest authorization data string
- bool get(string location )
- This will perform a simple HTTP GET request. This will be the most commonly used function to retrieve a document from a webserver. The location is just like the location you would use in your webbrowser.
- string getHTTPversion( )
- return thr current HTTP version setting
- string GetRequestHeader(string hname, optional coerce string def )
- Returns the value of the requested header, or default if not found
- string GetReturnHeader(string hname, optional coerce string def )
- Returns the value of the returned header, or default if not found
- int getTZoffset( )
- Return the timezone offset
- string GetValue(string key, array<GameInfo.KeyValuePair> Info, optional coerce string def )
- Returns the value of a
KeyValuePair
- bool head(string location )
- perform a HTTP HEAD request. This will only return the headers. Use this this if you only want to check the file info on the server and not the whole body.
- bool HttpRequest(string location, string Method )
- Start the HTTP request. Location can be a fully qualified url, or just the location on the configured server.
This is an internal function called by theget()
,head()
andpost()
functions. If you want to support additional HTTP requests you should subclass this class.
- bool httrace(string location )
- perform a HTTP TRACE request. This will simply cause the webserver to return the request it received. It's only usefull for debugging.
- InternalResolved(InternetLink.IpAddr Addr , optional bool bDontCache )
- hostname has been resolved
- bool IsAuthMethodSupported(EAuthMethod method )
- return if the authentication method is supported
- bool IsSupportedMethod( )
- Returns true when the request method is supported
- Logf(coerce string message, optional int level, optional coerce string Param1, optional coerce string Param2 )
- manage logging
- int now( )
- Returns the current timestamp. Warning this is not a valid UNIX timestamp because the timezone is unknown (e.g. timestamps are always GMT)
- bool OpenConnection( )
- start the download
- Opened( )
- will be called from HttpLink
- bool post(string location, optional string PostData )
- This will perform a simple HTTP POST request. If the PostData is not empty it will overwrite the current post data and set the content type to
application/x-www-form-urlencoded
.
- bool postex(string location, optional array<string> PostData )
- Perform a HTTP POST request using an array containing the postdata. if the array length > 0 it will overwrite the current post data. It will send the post data AS IS and doesn't set the content-type.
You might want to use thepost();
function together withsetFormData();
, that method is easier to use.
- ProccessWWWAuthenticate(string HeaderData, bool bProxyAuth )
- Process the header data of a WWW-Authenticate or Proxy-Authorization header
- ProcHeaders( )
- Will be called by ProcInput after all headers have been received
- ProcInput(string inline )
- Process the input
- string randString(optional int size, optional coerce string prefix )
- Generates a random string. The size defaults to 16. Prefix isn't included with the size;
- ReceivedText(string Line )
- called from HttpLink
- bool RemoveHeader(string hname )
- Remove a header, case insensitive. Returns true when the header is deleted
- ResolveFailed( )
- will be called from HttpLink when the resolve failed
- SendData(string data, optional bool bFlush )
- Send data buffered
if bFlush it will flush all remaining data (should be used for the last call)
- bool setFormData(string field, coerce string data, optional string contentType, optional string contentEncoding )
- Simple form of
setFormDataEx
when the data is only one line
- bool setFormDataEx(string field, array<string> data, optional string contentType, optional string contentEncoding )
- Add form data (used for
multipart/form-data
instead ofapplication/x-www-form-urlencoded
). This method makes it easier to add form-data. It doesn't clear the previous data, it will just append it. Form Data gives you more control over the actual data send. Also you don't have to escape the data.
It will also force the content type tomultipart/form-data
.
- bool setHTTPversion(optional string newver )
- Set the HTTP version, if empty the default will be used. Returns true when the version has been updated
- bool ShouldFollowRedirect(int retc, string method )
- returns true when a redirect should be followed, also updates headers for the next request.
- EAuthMethod StrToAuthMethod(coerce string method )
- string to EAuthMethod
- Timer( )
- timer is used for the conenection timeout.
- string UserAgent( )
- Returns the useragent string we use
Events
- Destroyed( )
- clean up as much as possible
- PreBeginPlay( )
- initialize some variables