Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
7.0 KiB

  1. //====== Copyright � 1996-2009, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: interface to http client
  4. //
  5. //=============================================================================
  6. #ifndef ISTEAMHTTP_H
  7. #define ISTEAMHTTP_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "isteamclient.h"
  12. #include "steamhttpenums.h"
  13. // Handle to a depot build
  14. typedef uint32 HTTPRequestHandle;
  15. #define INVALID_HTTPREQUEST_HANDLE 0
  16. //-----------------------------------------------------------------------------
  17. // Purpose: interface to building depots
  18. //-----------------------------------------------------------------------------
  19. class ISteamHTTP
  20. {
  21. public:
  22. // Initializes a new HTTP request, returning a handle to use in further operations on it. Requires
  23. // the method (GET or POST) and the absolute URL for the request. Only http requests (ie, not https) are
  24. // currently supported, so this string must start with http:// or https:// and should look like http://store.steampowered.com/app/250/
  25. // or such.
  26. virtual HTTPRequestHandle CreateHTTPRequest( EHTTPMethod eHTTPRequestMethod, const char *pchAbsoluteURL ) = 0;
  27. // Set a context value for the request, which will be returned in the HTTPRequestCompleted_t callback after
  28. // sending the request. This is just so the caller can easily keep track of which callbacks go with which request data.
  29. virtual bool SetHTTPRequestContextValue( HTTPRequestHandle hRequest, uint64 ulContextValue ) = 0;
  30. // Set a timeout in seconds for the HTTP request, must be called prior to sending the request. Default
  31. // timeout is 60 seconds if you don't call this. Returns false if the handle is invalid, or the request
  32. // has already been sent.
  33. virtual bool SetHTTPRequestNetworkActivityTimeout( HTTPRequestHandle hRequest, uint32 unTimeoutSeconds ) = 0;
  34. // Set a request header value for the request, must be called prior to sending the request. Will
  35. // return false if the handle is invalid or the request is already sent.
  36. virtual bool SetHTTPRequestHeaderValue( HTTPRequestHandle hRequest, const char *pchHeaderName, const char *pchHeaderValue ) = 0;
  37. // Set a GET or POST parameter value on the request, which is set will depend on the EHTTPMethod specified
  38. // when creating the request. Must be called prior to sending the request. Will return false if the
  39. // handle is invalid or the request is already sent.
  40. virtual bool SetHTTPRequestGetOrPostParameter( HTTPRequestHandle hRequest, const char *pchParamName, const char *pchParamValue ) = 0;
  41. // Sends the HTTP request, will return false on a bad handle, otherwise use SteamCallHandle to wait on
  42. // asyncronous response via callback.
  43. //
  44. // Note: If the user is in offline mode in Steam, then this will add a only-if-cached cache-control
  45. // header and only do a local cache lookup rather than sending any actual remote request.
  46. virtual bool SendHTTPRequest( HTTPRequestHandle hRequest, SteamAPICall_t *pCallHandle ) = 0;
  47. // Defers a request you have sent, the actual HTTP client code may have many requests queued, and this will move
  48. // the specified request to the tail of the queue. Returns false on invalid handle, or if the request is not yet sent.
  49. virtual bool DeferHTTPRequest( HTTPRequestHandle hRequest ) = 0;
  50. // Prioritizes a request you have sent, the actual HTTP client code may have many requests queued, and this will move
  51. // the specified request to the head of the queue. Returns false on invalid handle, or if the request is not yet sent.
  52. virtual bool PrioritizeHTTPRequest( HTTPRequestHandle hRequest ) = 0;
  53. // Checks if a response header is present in a HTTP response given a handle from HTTPRequestCompleted_t, also
  54. // returns the size of the header value if present so the caller and allocate a correctly sized buffer for
  55. // GetHTTPResponseHeaderValue.
  56. virtual bool GetHTTPResponseHeaderSize( HTTPRequestHandle hRequest, const char *pchHeaderName, uint32 *unResponseHeaderSize ) = 0;
  57. // Gets header values from a HTTP response given a handle from HTTPRequestCompleted_t, will return false if the
  58. // header is not present or if your buffer is too small to contain it's value. You should first call
  59. // BGetHTTPResponseHeaderSize to check for the presence of the header and to find out the size buffer needed.
  60. virtual bool GetHTTPResponseHeaderValue( HTTPRequestHandle hRequest, const char *pchHeaderName, uint8 *pHeaderValueBuffer, uint32 unBufferSize ) = 0;
  61. // Gets the size of the body data from a HTTP response given a handle from HTTPRequestCompleted_t, will return false if the
  62. // handle is invalid.
  63. virtual bool GetHTTPResponseBodySize( HTTPRequestHandle hRequest, uint32 *unBodySize ) = 0;
  64. // Gets the body data from a HTTP response given a handle from HTTPRequestCompleted_t, will return false if the
  65. // handle is invalid or if the provided buffer is not the correct size. Use BGetHTTPResponseBodySize first to find out
  66. // the correct buffer size to use.
  67. virtual bool GetHTTPResponseBodyData( HTTPRequestHandle hRequest, uint8 *pBodyDataBuffer, uint32 unBufferSize ) = 0;
  68. // Releases an HTTP response handle, should always be called to free resources after receiving a HTTPRequestCompleted_t
  69. // callback and finishing using the response.
  70. virtual bool ReleaseHTTPRequest( HTTPRequestHandle hRequest ) = 0;
  71. // Gets progress on downloading the body for the request. This will be zero unless a response header has already been
  72. // received which included a content-length field. For responses that contain no content-length it will report
  73. // zero for the duration of the request as the size is unknown until the connection closes.
  74. virtual bool GetHTTPDownloadProgressPct( HTTPRequestHandle hRequest, float *pflPercentOut ) = 0;
  75. // Sets the body for an HTTP Post request. Will fail and return false on a GET request, and will fail if POST params
  76. // have already been set for the request. Setting this raw body makes it the only contents for the post, the pchContentType
  77. // parameter will set the content-type header for the request so the server may know how to interpret the body.
  78. virtual bool SetHTTPRequestRawPostBody( HTTPRequestHandle hRequest, const char *pchContentType, uint8 *pubBody, uint32 unBodyLen ) = 0;
  79. };
  80. #define STEAMHTTP_INTERFACE_VERSION "STEAMHTTP_INTERFACE_VERSION001"
  81. struct HTTPRequestCompleted_t
  82. {
  83. enum { k_iCallback = k_iClientHTTPCallbacks + 1 };
  84. // Handle value for the request that has completed.
  85. HTTPRequestHandle m_hRequest;
  86. // Context value that the user defined on the request that this callback is associated with, 0 if
  87. // no context value was set.
  88. uint64 m_ulContextValue;
  89. // This will be true if we actually got any sort of response from the server (even an error).
  90. // It will be false if we failed due to an internal error or client side network failure.
  91. bool m_bRequestSuccessful;
  92. // Will be the HTTP status code value returned by the server, k_EHTTPStatusCode200OK is the normal
  93. // OK response, if you get something else you probably need to treat it as a failure.
  94. EHTTPStatusCode m_eStatusCode;
  95. };
  96. #endif // ISTEAMHTTP_H