isteamhttp.cs (16399B)
1 // This file is provided under The MIT License as part of Steamworks.NET. 2 // Copyright (c) 2013-2019 Riley Labrecque 3 // Please see the included LICENSE.txt for additional information. 4 5 // This file is automatically generated. 6 // Changes to this file will be reverted when you update Steamworks.NET 7 8 #if UNITY_ANDROID || UNITY_IOS || UNITY_TIZEN || UNITY_TVOS || UNITY_WEBGL || UNITY_WSA || UNITY_PS4 || UNITY_WII || UNITY_XBOXONE || UNITY_SWITCH 9 #define DISABLESTEAMWORKS 10 #endif 11 12 #if !DISABLESTEAMWORKS 13 14 using System.Runtime.InteropServices; 15 using IntPtr = System.IntPtr; 16 17 namespace Steamworks { 18 public static class SteamHTTP { 19 /// <summary> 20 /// <para> Initializes a new HTTP request, returning a handle to use in further operations on it. Requires</para> 21 /// <para> the method (GET or POST) and the absolute URL for the request. Both http and https are supported,</para> 22 /// <para> so this string must start with http:// or https:// and should look like http://store.steampowered.com/app/250/</para> 23 /// <para> or such.</para> 24 /// </summary> 25 public static HTTPRequestHandle CreateHTTPRequest(EHTTPMethod eHTTPRequestMethod, string pchAbsoluteURL) { 26 InteropHelp.TestIfAvailableClient(); 27 using (var pchAbsoluteURL2 = new InteropHelp.UTF8StringHandle(pchAbsoluteURL)) { 28 return (HTTPRequestHandle)NativeMethods.ISteamHTTP_CreateHTTPRequest(CSteamAPIContext.GetSteamHTTP(), eHTTPRequestMethod, pchAbsoluteURL2); 29 } 30 } 31 32 /// <summary> 33 /// <para> Set a context value for the request, which will be returned in the HTTPRequestCompleted_t callback after</para> 34 /// <para> sending the request. This is just so the caller can easily keep track of which callbacks go with which request data.</para> 35 /// </summary> 36 public static bool SetHTTPRequestContextValue(HTTPRequestHandle hRequest, ulong ulContextValue) { 37 InteropHelp.TestIfAvailableClient(); 38 return NativeMethods.ISteamHTTP_SetHTTPRequestContextValue(CSteamAPIContext.GetSteamHTTP(), hRequest, ulContextValue); 39 } 40 41 /// <summary> 42 /// <para> Set a timeout in seconds for the HTTP request, must be called prior to sending the request. Default</para> 43 /// <para> timeout is 60 seconds if you don't call this. Returns false if the handle is invalid, or the request</para> 44 /// <para> has already been sent.</para> 45 /// </summary> 46 public static bool SetHTTPRequestNetworkActivityTimeout(HTTPRequestHandle hRequest, uint unTimeoutSeconds) { 47 InteropHelp.TestIfAvailableClient(); 48 return NativeMethods.ISteamHTTP_SetHTTPRequestNetworkActivityTimeout(CSteamAPIContext.GetSteamHTTP(), hRequest, unTimeoutSeconds); 49 } 50 51 /// <summary> 52 /// <para> Set a request header value for the request, must be called prior to sending the request. Will</para> 53 /// <para> return false if the handle is invalid or the request is already sent.</para> 54 /// </summary> 55 public static bool SetHTTPRequestHeaderValue(HTTPRequestHandle hRequest, string pchHeaderName, string pchHeaderValue) { 56 InteropHelp.TestIfAvailableClient(); 57 using (var pchHeaderName2 = new InteropHelp.UTF8StringHandle(pchHeaderName)) 58 using (var pchHeaderValue2 = new InteropHelp.UTF8StringHandle(pchHeaderValue)) { 59 return NativeMethods.ISteamHTTP_SetHTTPRequestHeaderValue(CSteamAPIContext.GetSteamHTTP(), hRequest, pchHeaderName2, pchHeaderValue2); 60 } 61 } 62 63 /// <summary> 64 /// <para> Set a GET or POST parameter value on the request, which is set will depend on the EHTTPMethod specified</para> 65 /// <para> when creating the request. Must be called prior to sending the request. Will return false if the</para> 66 /// <para> handle is invalid or the request is already sent.</para> 67 /// </summary> 68 public static bool SetHTTPRequestGetOrPostParameter(HTTPRequestHandle hRequest, string pchParamName, string pchParamValue) { 69 InteropHelp.TestIfAvailableClient(); 70 using (var pchParamName2 = new InteropHelp.UTF8StringHandle(pchParamName)) 71 using (var pchParamValue2 = new InteropHelp.UTF8StringHandle(pchParamValue)) { 72 return NativeMethods.ISteamHTTP_SetHTTPRequestGetOrPostParameter(CSteamAPIContext.GetSteamHTTP(), hRequest, pchParamName2, pchParamValue2); 73 } 74 } 75 76 /// <summary> 77 /// <para> Sends the HTTP request, will return false on a bad handle, otherwise use SteamCallHandle to wait on</para> 78 /// <para> asynchronous response via callback.</para> 79 /// <para> Note: If the user is in offline mode in Steam, then this will add a only-if-cached cache-control</para> 80 /// <para> header and only do a local cache lookup rather than sending any actual remote request.</para> 81 /// </summary> 82 public static bool SendHTTPRequest(HTTPRequestHandle hRequest, out SteamAPICall_t pCallHandle) { 83 InteropHelp.TestIfAvailableClient(); 84 return NativeMethods.ISteamHTTP_SendHTTPRequest(CSteamAPIContext.GetSteamHTTP(), hRequest, out pCallHandle); 85 } 86 87 /// <summary> 88 /// <para> Sends the HTTP request, will return false on a bad handle, otherwise use SteamCallHandle to wait on</para> 89 /// <para> asynchronous response via callback for completion, and listen for HTTPRequestHeadersReceived_t and</para> 90 /// <para> HTTPRequestDataReceived_t callbacks while streaming.</para> 91 /// </summary> 92 public static bool SendHTTPRequestAndStreamResponse(HTTPRequestHandle hRequest, out SteamAPICall_t pCallHandle) { 93 InteropHelp.TestIfAvailableClient(); 94 return NativeMethods.ISteamHTTP_SendHTTPRequestAndStreamResponse(CSteamAPIContext.GetSteamHTTP(), hRequest, out pCallHandle); 95 } 96 97 /// <summary> 98 /// <para> Defers a request you have sent, the actual HTTP client code may have many requests queued, and this will move</para> 99 /// <para> the specified request to the tail of the queue. Returns false on invalid handle, or if the request is not yet sent.</para> 100 /// </summary> 101 public static bool DeferHTTPRequest(HTTPRequestHandle hRequest) { 102 InteropHelp.TestIfAvailableClient(); 103 return NativeMethods.ISteamHTTP_DeferHTTPRequest(CSteamAPIContext.GetSteamHTTP(), hRequest); 104 } 105 106 /// <summary> 107 /// <para> Prioritizes a request you have sent, the actual HTTP client code may have many requests queued, and this will move</para> 108 /// <para> the specified request to the head of the queue. Returns false on invalid handle, or if the request is not yet sent.</para> 109 /// </summary> 110 public static bool PrioritizeHTTPRequest(HTTPRequestHandle hRequest) { 111 InteropHelp.TestIfAvailableClient(); 112 return NativeMethods.ISteamHTTP_PrioritizeHTTPRequest(CSteamAPIContext.GetSteamHTTP(), hRequest); 113 } 114 115 /// <summary> 116 /// <para> Checks if a response header is present in a HTTP response given a handle from HTTPRequestCompleted_t, also</para> 117 /// <para> returns the size of the header value if present so the caller and allocate a correctly sized buffer for</para> 118 /// <para> GetHTTPResponseHeaderValue.</para> 119 /// </summary> 120 public static bool GetHTTPResponseHeaderSize(HTTPRequestHandle hRequest, string pchHeaderName, out uint unResponseHeaderSize) { 121 InteropHelp.TestIfAvailableClient(); 122 using (var pchHeaderName2 = new InteropHelp.UTF8StringHandle(pchHeaderName)) { 123 return NativeMethods.ISteamHTTP_GetHTTPResponseHeaderSize(CSteamAPIContext.GetSteamHTTP(), hRequest, pchHeaderName2, out unResponseHeaderSize); 124 } 125 } 126 127 /// <summary> 128 /// <para> Gets header values from a HTTP response given a handle from HTTPRequestCompleted_t, will return false if the</para> 129 /// <para> header is not present or if your buffer is too small to contain it's value. You should first call</para> 130 /// <para> BGetHTTPResponseHeaderSize to check for the presence of the header and to find out the size buffer needed.</para> 131 /// </summary> 132 public static bool GetHTTPResponseHeaderValue(HTTPRequestHandle hRequest, string pchHeaderName, byte[] pHeaderValueBuffer, uint unBufferSize) { 133 InteropHelp.TestIfAvailableClient(); 134 using (var pchHeaderName2 = new InteropHelp.UTF8StringHandle(pchHeaderName)) { 135 return NativeMethods.ISteamHTTP_GetHTTPResponseHeaderValue(CSteamAPIContext.GetSteamHTTP(), hRequest, pchHeaderName2, pHeaderValueBuffer, unBufferSize); 136 } 137 } 138 139 /// <summary> 140 /// <para> Gets the size of the body data from a HTTP response given a handle from HTTPRequestCompleted_t, will return false if the</para> 141 /// <para> handle is invalid.</para> 142 /// </summary> 143 public static bool GetHTTPResponseBodySize(HTTPRequestHandle hRequest, out uint unBodySize) { 144 InteropHelp.TestIfAvailableClient(); 145 return NativeMethods.ISteamHTTP_GetHTTPResponseBodySize(CSteamAPIContext.GetSteamHTTP(), hRequest, out unBodySize); 146 } 147 148 /// <summary> 149 /// <para> Gets the body data from a HTTP response given a handle from HTTPRequestCompleted_t, will return false if the</para> 150 /// <para> 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</para> 151 /// <para> the correct buffer size to use.</para> 152 /// </summary> 153 public static bool GetHTTPResponseBodyData(HTTPRequestHandle hRequest, byte[] pBodyDataBuffer, uint unBufferSize) { 154 InteropHelp.TestIfAvailableClient(); 155 return NativeMethods.ISteamHTTP_GetHTTPResponseBodyData(CSteamAPIContext.GetSteamHTTP(), hRequest, pBodyDataBuffer, unBufferSize); 156 } 157 158 /// <summary> 159 /// <para> Gets the body data from a streaming HTTP response given a handle from HTTPRequestDataReceived_t. Will return false if the</para> 160 /// <para> handle is invalid or is to a non-streaming response (meaning it wasn't sent with SendHTTPRequestAndStreamResponse), or if the buffer size and offset</para> 161 /// <para> do not match the size and offset sent in HTTPRequestDataReceived_t.</para> 162 /// </summary> 163 public static bool GetHTTPStreamingResponseBodyData(HTTPRequestHandle hRequest, uint cOffset, byte[] pBodyDataBuffer, uint unBufferSize) { 164 InteropHelp.TestIfAvailableClient(); 165 return NativeMethods.ISteamHTTP_GetHTTPStreamingResponseBodyData(CSteamAPIContext.GetSteamHTTP(), hRequest, cOffset, pBodyDataBuffer, unBufferSize); 166 } 167 168 /// <summary> 169 /// <para> Releases an HTTP response handle, should always be called to free resources after receiving a HTTPRequestCompleted_t</para> 170 /// <para> callback and finishing using the response.</para> 171 /// </summary> 172 public static bool ReleaseHTTPRequest(HTTPRequestHandle hRequest) { 173 InteropHelp.TestIfAvailableClient(); 174 return NativeMethods.ISteamHTTP_ReleaseHTTPRequest(CSteamAPIContext.GetSteamHTTP(), hRequest); 175 } 176 177 /// <summary> 178 /// <para> Gets progress on downloading the body for the request. This will be zero unless a response header has already been</para> 179 /// <para> received which included a content-length field. For responses that contain no content-length it will report</para> 180 /// <para> zero for the duration of the request as the size is unknown until the connection closes.</para> 181 /// </summary> 182 public static bool GetHTTPDownloadProgressPct(HTTPRequestHandle hRequest, out float pflPercentOut) { 183 InteropHelp.TestIfAvailableClient(); 184 return NativeMethods.ISteamHTTP_GetHTTPDownloadProgressPct(CSteamAPIContext.GetSteamHTTP(), hRequest, out pflPercentOut); 185 } 186 187 /// <summary> 188 /// <para> Sets the body for an HTTP Post request. Will fail and return false on a GET request, and will fail if POST params</para> 189 /// <para> have already been set for the request. Setting this raw body makes it the only contents for the post, the pchContentType</para> 190 /// <para> parameter will set the content-type header for the request so the server may know how to interpret the body.</para> 191 /// </summary> 192 public static bool SetHTTPRequestRawPostBody(HTTPRequestHandle hRequest, string pchContentType, byte[] pubBody, uint unBodyLen) { 193 InteropHelp.TestIfAvailableClient(); 194 using (var pchContentType2 = new InteropHelp.UTF8StringHandle(pchContentType)) { 195 return NativeMethods.ISteamHTTP_SetHTTPRequestRawPostBody(CSteamAPIContext.GetSteamHTTP(), hRequest, pchContentType2, pubBody, unBodyLen); 196 } 197 } 198 199 /// <summary> 200 /// <para> Creates a cookie container handle which you must later free with ReleaseCookieContainer(). If bAllowResponsesToModify=true</para> 201 /// <para> than any response to your requests using this cookie container may add new cookies which may be transmitted with</para> 202 /// <para> future requests. If bAllowResponsesToModify=false than only cookies you explicitly set will be sent. This API is just for</para> 203 /// <para> during process lifetime, after steam restarts no cookies are persisted and you have no way to access the cookie container across</para> 204 /// <para> repeat executions of your process.</para> 205 /// </summary> 206 public static HTTPCookieContainerHandle CreateCookieContainer(bool bAllowResponsesToModify) { 207 InteropHelp.TestIfAvailableClient(); 208 return (HTTPCookieContainerHandle)NativeMethods.ISteamHTTP_CreateCookieContainer(CSteamAPIContext.GetSteamHTTP(), bAllowResponsesToModify); 209 } 210 211 /// <summary> 212 /// <para> Release a cookie container you are finished using, freeing it's memory</para> 213 /// </summary> 214 public static bool ReleaseCookieContainer(HTTPCookieContainerHandle hCookieContainer) { 215 InteropHelp.TestIfAvailableClient(); 216 return NativeMethods.ISteamHTTP_ReleaseCookieContainer(CSteamAPIContext.GetSteamHTTP(), hCookieContainer); 217 } 218 219 /// <summary> 220 /// <para> Adds a cookie to the specified cookie container that will be used with future requests.</para> 221 /// </summary> 222 public static bool SetCookie(HTTPCookieContainerHandle hCookieContainer, string pchHost, string pchUrl, string pchCookie) { 223 InteropHelp.TestIfAvailableClient(); 224 using (var pchHost2 = new InteropHelp.UTF8StringHandle(pchHost)) 225 using (var pchUrl2 = new InteropHelp.UTF8StringHandle(pchUrl)) 226 using (var pchCookie2 = new InteropHelp.UTF8StringHandle(pchCookie)) { 227 return NativeMethods.ISteamHTTP_SetCookie(CSteamAPIContext.GetSteamHTTP(), hCookieContainer, pchHost2, pchUrl2, pchCookie2); 228 } 229 } 230 231 /// <summary> 232 /// <para> Set the cookie container to use for a HTTP request</para> 233 /// </summary> 234 public static bool SetHTTPRequestCookieContainer(HTTPRequestHandle hRequest, HTTPCookieContainerHandle hCookieContainer) { 235 InteropHelp.TestIfAvailableClient(); 236 return NativeMethods.ISteamHTTP_SetHTTPRequestCookieContainer(CSteamAPIContext.GetSteamHTTP(), hRequest, hCookieContainer); 237 } 238 239 /// <summary> 240 /// <para> 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</para> 241 /// </summary> 242 public static bool SetHTTPRequestUserAgentInfo(HTTPRequestHandle hRequest, string pchUserAgentInfo) { 243 InteropHelp.TestIfAvailableClient(); 244 using (var pchUserAgentInfo2 = new InteropHelp.UTF8StringHandle(pchUserAgentInfo)) { 245 return NativeMethods.ISteamHTTP_SetHTTPRequestUserAgentInfo(CSteamAPIContext.GetSteamHTTP(), hRequest, pchUserAgentInfo2); 246 } 247 } 248 249 /// <summary> 250 /// <para> Disable or re-enable verification of SSL/TLS certificates.</para> 251 /// <para> By default, certificates are checked for all HTTPS requests.</para> 252 /// </summary> 253 public static bool SetHTTPRequestRequiresVerifiedCertificate(HTTPRequestHandle hRequest, bool bRequireVerifiedCertificate) { 254 InteropHelp.TestIfAvailableClient(); 255 return NativeMethods.ISteamHTTP_SetHTTPRequestRequiresVerifiedCertificate(CSteamAPIContext.GetSteamHTTP(), hRequest, bRequireVerifiedCertificate); 256 } 257 258 /// <summary> 259 /// <para> Set an absolute timeout on the HTTP request, this is just a total time timeout different than the network activity timeout</para> 260 /// <para> which can bump everytime we get more data</para> 261 /// </summary> 262 public static bool SetHTTPRequestAbsoluteTimeoutMS(HTTPRequestHandle hRequest, uint unMilliseconds) { 263 InteropHelp.TestIfAvailableClient(); 264 return NativeMethods.ISteamHTTP_SetHTTPRequestAbsoluteTimeoutMS(CSteamAPIContext.GetSteamHTTP(), hRequest, unMilliseconds); 265 } 266 267 /// <summary> 268 /// <para> Check if the reason the request failed was because we timed it out (rather than some harder failure)</para> 269 /// </summary> 270 public static bool GetHTTPRequestWasTimedOut(HTTPRequestHandle hRequest, out bool pbWasTimedOut) { 271 InteropHelp.TestIfAvailableClient(); 272 return NativeMethods.ISteamHTTP_GetHTTPRequestWasTimedOut(CSteamAPIContext.GetSteamHTTP(), hRequest, out pbWasTimedOut); 273 } 274 } 275 } 276 277 #endif // !DISABLESTEAMWORKS