Rise
The Vieneo Province
Loading...
Searching...
No Matches
isteamhttp.h
Go to the documentation of this file.
1//====== Copyright © 1996-2009, Valve Corporation, All rights reserved. =======
2//
3// Purpose: interface to http client
4//
5//=============================================================================
6
7#ifndef ISTEAMHTTP_H
8#define ISTEAMHTTP_H
9#ifdef _WIN32
10#pragma once
11#endif
12
13#include "steam_api_common.h"
14#include "steamhttpenums.h"
15
16// Handle to a HTTP Request handle
18#define INVALID_HTTPREQUEST_HANDLE 0
19
21#define INVALID_HTTPCOOKIE_HANDLE 0
22
23//-----------------------------------------------------------------------------
24// Purpose: interface to http client
25//-----------------------------------------------------------------------------
27{
28public:
29
30 // Initializes a new HTTP request, returning a handle to use in further operations on it. Requires
31 // the method (GET or POST) and the absolute URL for the request. Both http and https are supported,
32 // so this string must start with http:// or https:// and should look like http://store.steampowered.com/app/250/
33 // or such.
34 virtual HTTPRequestHandle CreateHTTPRequest( EHTTPMethod eHTTPRequestMethod, const char *pchAbsoluteURL ) = 0;
35
36 // Set a context value for the request, which will be returned in the HTTPRequestCompleted_t callback after
37 // sending the request. This is just so the caller can easily keep track of which callbacks go with which request data.
38 virtual bool SetHTTPRequestContextValue( HTTPRequestHandle hRequest, uint64 ulContextValue ) = 0;
39
40 // Set a timeout in seconds for the HTTP request, must be called prior to sending the request. Default
41 // timeout is 60 seconds if you don't call this. Returns false if the handle is invalid, or the request
42 // has already been sent.
43 virtual bool SetHTTPRequestNetworkActivityTimeout( HTTPRequestHandle hRequest, uint32 unTimeoutSeconds ) = 0;
44
45 // Set a request header value for the request, must be called prior to sending the request. Will
46 // return false if the handle is invalid or the request is already sent.
47 virtual bool SetHTTPRequestHeaderValue( HTTPRequestHandle hRequest, const char *pchHeaderName, const char *pchHeaderValue ) = 0;
48
49 // Set a GET or POST parameter value on the request, which is set will depend on the EHTTPMethod specified
50 // when creating the request. Must be called prior to sending the request. Will return false if the
51 // handle is invalid or the request is already sent.
52 virtual bool SetHTTPRequestGetOrPostParameter( HTTPRequestHandle hRequest, const char *pchParamName, const char *pchParamValue ) = 0;
53
54 // Sends the HTTP request, will return false on a bad handle, otherwise use SteamCallHandle to wait on
55 // asynchronous response via callback.
56 //
57 // Note: If the user is in offline mode in Steam, then this will add a only-if-cached cache-control
58 // header and only do a local cache lookup rather than sending any actual remote request.
59 virtual bool SendHTTPRequest( HTTPRequestHandle hRequest, SteamAPICall_t *pCallHandle ) = 0;
60
61 // Sends the HTTP request, will return false on a bad handle, otherwise use SteamCallHandle to wait on
62 // asynchronous response via callback for completion, and listen for HTTPRequestHeadersReceived_t and
63 // HTTPRequestDataReceived_t callbacks while streaming.
64 virtual bool SendHTTPRequestAndStreamResponse( HTTPRequestHandle hRequest, SteamAPICall_t *pCallHandle ) = 0;
65
66 // Defers a request you have sent, the actual HTTP client code may have many requests queued, and this will move
67 // the specified request to the tail of the queue. Returns false on invalid handle, or if the request is not yet sent.
68 virtual bool DeferHTTPRequest( HTTPRequestHandle hRequest ) = 0;
69
70 // Prioritizes a request you have sent, the actual HTTP client code may have many requests queued, and this will move
71 // the specified request to the head of the queue. Returns false on invalid handle, or if the request is not yet sent.
72 virtual bool PrioritizeHTTPRequest( HTTPRequestHandle hRequest ) = 0;
73
74 // Checks if a response header is present in a HTTP response given a handle from HTTPRequestCompleted_t, also
75 // returns the size of the header value if present so the caller and allocate a correctly sized buffer for
76 // GetHTTPResponseHeaderValue.
77 virtual bool GetHTTPResponseHeaderSize( HTTPRequestHandle hRequest, const char *pchHeaderName, uint32 *unResponseHeaderSize ) = 0;
78
79 // Gets header values from a HTTP response given a handle from HTTPRequestCompleted_t, will return false if the
80 // header is not present or if your buffer is too small to contain it's value. You should first call
81 // BGetHTTPResponseHeaderSize to check for the presence of the header and to find out the size buffer needed.
82 virtual bool GetHTTPResponseHeaderValue( HTTPRequestHandle hRequest, const char *pchHeaderName, uint8 *pHeaderValueBuffer, uint32 unBufferSize ) = 0;
83
84 // Gets the size of the body data from a HTTP response given a handle from HTTPRequestCompleted_t, will return false if the
85 // handle is invalid.
86 virtual bool GetHTTPResponseBodySize( HTTPRequestHandle hRequest, uint32 *unBodySize ) = 0;
87
88 // Gets the body data from a HTTP response given a handle from HTTPRequestCompleted_t, will return false if the
89 // handle is invalid or is to a streaming response, or if the provided buffer is not the correct size. Use BGetHTTPResponseBodySize first to find out
90 // the correct buffer size to use.
91 virtual bool GetHTTPResponseBodyData( HTTPRequestHandle hRequest, uint8 *pBodyDataBuffer, uint32 unBufferSize ) = 0;
92
93 // Gets the body data from a streaming HTTP response given a handle from HTTPRequestDataReceived_t. Will return false if the
94 // handle is invalid or is to a non-streaming response (meaning it wasn't sent with SendHTTPRequestAndStreamResponse), or if the buffer size and offset
95 // do not match the size and offset sent in HTTPRequestDataReceived_t.
96 virtual bool GetHTTPStreamingResponseBodyData( HTTPRequestHandle hRequest, uint32 cOffset, uint8 *pBodyDataBuffer, uint32 unBufferSize ) = 0;
97
98 // Releases an HTTP response handle, should always be called to free resources after receiving a HTTPRequestCompleted_t
99 // callback and finishing using the response.
100 virtual bool ReleaseHTTPRequest( HTTPRequestHandle hRequest ) = 0;
101
102 // Gets progress on downloading the body for the request. This will be zero unless a response header has already been
103 // received which included a content-length field. For responses that contain no content-length it will report
104 // zero for the duration of the request as the size is unknown until the connection closes.
105 virtual bool GetHTTPDownloadProgressPct( HTTPRequestHandle hRequest, float *pflPercentOut ) = 0;
106
107 // Sets the body for an HTTP Post request. Will fail and return false on a GET request, and will fail if POST params
108 // have already been set for the request. Setting this raw body makes it the only contents for the post, the pchContentType
109 // parameter will set the content-type header for the request so the server may know how to interpret the body.
110 virtual bool SetHTTPRequestRawPostBody( HTTPRequestHandle hRequest, const char *pchContentType, uint8 *pubBody, uint32 unBodyLen ) = 0;
111
112 // Creates a cookie container handle which you must later free with ReleaseCookieContainer(). If bAllowResponsesToModify=true
113 // than any response to your requests using this cookie container may add new cookies which may be transmitted with
114 // future requests. If bAllowResponsesToModify=false than only cookies you explicitly set will be sent. This API is just for
115 // during process lifetime, after steam restarts no cookies are persisted and you have no way to access the cookie container across
116 // repeat executions of your process.
117 virtual HTTPCookieContainerHandle CreateCookieContainer( bool bAllowResponsesToModify ) = 0;
118
119 // Release a cookie container you are finished using, freeing it's memory
120 virtual bool ReleaseCookieContainer( HTTPCookieContainerHandle hCookieContainer ) = 0;
121
122 // Adds a cookie to the specified cookie container that will be used with future requests.
123 virtual bool SetCookie( HTTPCookieContainerHandle hCookieContainer, const char *pchHost, const char *pchUrl, const char *pchCookie ) = 0;
124
125 // Set the cookie container to use for a HTTP request
126 virtual bool SetHTTPRequestCookieContainer( HTTPRequestHandle hRequest, HTTPCookieContainerHandle hCookieContainer ) = 0;
127
128 // Set the extra user agent info for a request, this doesn't clobber the normal user agent, it just adds the extra info on the end
129 virtual bool SetHTTPRequestUserAgentInfo( HTTPRequestHandle hRequest, const char *pchUserAgentInfo ) = 0;
130
131 // Disable or re-enable verification of SSL/TLS certificates.
132 // By default, certificates are checked for all HTTPS requests.
133 virtual bool SetHTTPRequestRequiresVerifiedCertificate( HTTPRequestHandle hRequest, bool bRequireVerifiedCertificate ) = 0;
134
135 // Set an absolute timeout on the HTTP request, this is just a total time timeout different than the network activity timeout
136 // which can bump everytime we get more data
137 virtual bool SetHTTPRequestAbsoluteTimeoutMS( HTTPRequestHandle hRequest, uint32 unMilliseconds ) = 0;
138
139 // Check if the reason the request failed was because we timed it out (rather than some harder failure)
140 virtual bool GetHTTPRequestWasTimedOut( HTTPRequestHandle hRequest, bool *pbWasTimedOut ) = 0;
141};
142
143#define STEAMHTTP_INTERFACE_VERSION "STEAMHTTP_INTERFACE_VERSION003"
144
145// Global interface accessor
148
149// Global accessor for the gameserver client
152
153// callbacks
154#if defined( VALVE_CALLBACK_PACK_SMALL )
155#pragma pack( push, 4 )
156#elif defined( VALVE_CALLBACK_PACK_LARGE )
157#pragma pack( push, 8 )
158#else
159#error steam_api_common.h should define VALVE_CALLBACK_PACK_xxx
160#endif
161
163{
165
166 // Handle value for the request that has completed.
168
169 // Context value that the user defined on the request that this callback is associated with, 0 if
170 // no context value was set.
172
173 // This will be true if we actually got any sort of response from the server (even an error).
174 // It will be false if we failed due to an internal error or client side network failure.
176
177 // Will be the HTTP status code value returned by the server, k_EHTTPStatusCode200OK is the normal
178 // OK response, if you get something else you probably need to treat it as a failure.
180
181 uint32 m_unBodySize; // Same as GetHTTPResponseBodySize()
182};
183
184
186{
188
189 // Handle value for the request that has received headers.
191
192 // Context value that the user defined on the request that this callback is associated with, 0 if
193 // no context value was set.
195};
196
198{
200
201 // Handle value for the request that has received data.
203
204 // Context value that the user defined on the request that this callback is associated with, 0 if
205 // no context value was set.
207
208
209 // Offset to provide to GetHTTPStreamingResponseBodyData to get this chunk of data
211
212 // Size to provide to GetHTTPStreamingResponseBodyData to get this chunk of data
214};
215
216
217#pragma pack( pop )
218
219#endif // ISTEAMHTTP_H
virtual bool SetHTTPRequestRawPostBody(HTTPRequestHandle hRequest, const char *pchContentType, uint8 *pubBody, uint32 unBodyLen)=0
virtual bool GetHTTPStreamingResponseBodyData(HTTPRequestHandle hRequest, uint32 cOffset, uint8 *pBodyDataBuffer, uint32 unBufferSize)=0
virtual bool GetHTTPResponseBodySize(HTTPRequestHandle hRequest, uint32 *unBodySize)=0
virtual bool SendHTTPRequest(HTTPRequestHandle hRequest, SteamAPICall_t *pCallHandle)=0
virtual bool GetHTTPResponseHeaderSize(HTTPRequestHandle hRequest, const char *pchHeaderName, uint32 *unResponseHeaderSize)=0
virtual bool SetHTTPRequestUserAgentInfo(HTTPRequestHandle hRequest, const char *pchUserAgentInfo)=0
virtual bool GetHTTPDownloadProgressPct(HTTPRequestHandle hRequest, float *pflPercentOut)=0
virtual bool GetHTTPResponseHeaderValue(HTTPRequestHandle hRequest, const char *pchHeaderName, uint8 *pHeaderValueBuffer, uint32 unBufferSize)=0
virtual bool SetHTTPRequestAbsoluteTimeoutMS(HTTPRequestHandle hRequest, uint32 unMilliseconds)=0
virtual bool ReleaseCookieContainer(HTTPCookieContainerHandle hCookieContainer)=0
virtual bool SetHTTPRequestContextValue(HTTPRequestHandle hRequest, uint64 ulContextValue)=0
virtual bool SetHTTPRequestNetworkActivityTimeout(HTTPRequestHandle hRequest, uint32 unTimeoutSeconds)=0
virtual bool SetHTTPRequestHeaderValue(HTTPRequestHandle hRequest, const char *pchHeaderName, const char *pchHeaderValue)=0
virtual bool SetHTTPRequestGetOrPostParameter(HTTPRequestHandle hRequest, const char *pchParamName, const char *pchParamValue)=0
virtual bool GetHTTPRequestWasTimedOut(HTTPRequestHandle hRequest, bool *pbWasTimedOut)=0
virtual bool SetHTTPRequestCookieContainer(HTTPRequestHandle hRequest, HTTPCookieContainerHandle hCookieContainer)=0
virtual bool SetCookie(HTTPCookieContainerHandle hCookieContainer, const char *pchHost, const char *pchUrl, const char *pchCookie)=0
virtual bool SendHTTPRequestAndStreamResponse(HTTPRequestHandle hRequest, SteamAPICall_t *pCallHandle)=0
virtual HTTPCookieContainerHandle CreateCookieContainer(bool bAllowResponsesToModify)=0
virtual bool ReleaseHTTPRequest(HTTPRequestHandle hRequest)=0
virtual HTTPRequestHandle CreateHTTPRequest(EHTTPMethod eHTTPRequestMethod, const char *pchAbsoluteURL)=0
virtual bool GetHTTPResponseBodyData(HTTPRequestHandle hRequest, uint8 *pBodyDataBuffer, uint32 unBufferSize)=0
virtual bool SetHTTPRequestRequiresVerifiedCertificate(HTTPRequestHandle hRequest, bool bRequireVerifiedCertificate)=0
virtual bool DeferHTTPRequest(HTTPRequestHandle hRequest)=0
virtual bool PrioritizeHTTPRequest(HTTPRequestHandle hRequest)=0
ISteamHTTP * SteamHTTP()
uint32 HTTPRequestHandle
Definition isteamhttp.h:17
ISteamHTTP * SteamGameServerHTTP()
#define STEAMHTTP_INTERFACE_VERSION
Definition isteamhttp.h:143
uint32 HTTPCookieContainerHandle
Definition isteamhttp.h:20
const char *typedef uint32(S_CALLTYPE *SteamAPI_CheckCallbackRegistered_t)(int iCallbackNum)
#define STEAM_DEFINE_USER_INTERFACE_ACCESSOR(type, name, version)
@ k_iSteamHTTPCallbacks
#define STEAM_DEFINE_GAMESERVER_INTERFACE_ACCESSOR(type, name, version)
EHTTPMethod
EHTTPStatusCode
unsigned long long uint64
Definition steamtypes.h:60
uint64 SteamAPICall_t
Definition steamtypes.h:93
unsigned char uint8
Definition steamtypes.h:11
HTTPRequestHandle m_hRequest
Definition isteamhttp.h:167
EHTTPStatusCode m_eStatusCode
Definition isteamhttp.h:179
HTTPRequestHandle m_hRequest
Definition isteamhttp.h:202
HTTPRequestHandle m_hRequest
Definition isteamhttp.h:190