12#include "azure/core/dll_import_export.hpp"
16#include "azure/core/internal/contract.hpp"
28#include <unordered_set>
31#if defined(_azure_TESTING_BUILD)
33namespace Azure {
namespace Core {
namespace Test {
34 class TestHttp_getters_Test;
35 class TestHttp_query_parameter_Test;
36 class TestHttp_RequestStartTry_Test;
37 class TestURL_getters_Test;
38 class TestURL_query_parameter_Test;
39 class TransportAdapter_headWithStream_Test;
40 class TransportAdapter_putWithStream_Test;
41 class TransportAdapter_deleteRequestWithStream_Test;
42 class TransportAdapter_patchWithStream_Test;
43 class TransportAdapter_putWithStreamOnFail_Test;
44 class TransportAdapter_SizePutFromFile_Test;
45 class TransportAdapter_SizePutFromFileDefault_Test;
46 class TransportAdapter_SizePutFromFileBiggerPage_Test;
50namespace Azure {
namespace Core {
namespace Http {
103 explicit HttpMethod(std::string value) : m_value(std::move(value)) {}
124 const std::string&
ToString()
const {
return m_value; }
172 namespace Policies {
namespace _internal {
183 friend class Azure::Core::Http::Policies::_internal::RetryPolicy;
184#if defined(_azure_TESTING_BUILD)
186 friend class Azure::Core::Test::TestHttp_getters_Test;
187 friend class Azure::Core::Test::TestHttp_query_parameter_Test;
188 friend class Azure::Core::Test::TestHttp_RequestStartTry_Test;
189 friend class Azure::Core::Test::TestURL_getters_Test;
190 friend class Azure::Core::Test::TestURL_query_parameter_Test;
192 friend class Azure::Core::Test::TransportAdapter_headWithStream_Test;
193 friend class Azure::Core::Test::TransportAdapter_putWithStream_Test;
194 friend class Azure::Core::Test::TransportAdapter_deleteRequestWithStream_Test;
195 friend class Azure::Core::Test::TransportAdapter_patchWithStream_Test;
196 friend class Azure::Core::Test::TransportAdapter_putWithStreamOnFail_Test;
197 friend class Azure::Core::Test::TransportAdapter_SizePutFromFile_Test;
198 friend class Azure::Core::Test::TransportAdapter_SizePutFromFileDefault_Test;
199 friend class Azure::Core::Test::TransportAdapter_SizePutFromFileBiggerPage_Test;
211 bool m_retryModeEnabled{
false};
212 bool m_shouldBufferResponse{
true};
232 bool shouldBufferResponse)
233 : m_method(std::move(httpMethod)), m_url(std::move(url)), m_bodyStream(bodyStream),
234 m_retryModeEnabled(false), m_shouldBufferResponse(shouldBufferResponse)
247 :
Request(httpMethod, std::move(url), bodyStream, true)
280 void SetHeader(std::string
const& name, std::string
const& value);
346 struct RawResponseHelpers final
358 static void InsertHeaderWithValidation(
360 std::string
const& headerName,
361 std::string
const& headerValue);
363 static void inline SetHeader(
365 uint8_t
const*
const first,
366 uint8_t
const*
const last)
370 auto end = std::find(start, last,
':');
374 throw std::invalid_argument(
"Invalid header. No delimiter ':' found.");
378 auto const headerName
379 = Azure::Core::_internal::StringExtensions::ToLower(std::string(start, end));
381 while (start < last && (*start ==
' ' || *start ==
'\t'))
386 end = std::find(start, last,
'\r');
387 auto headerValue = std::string(start, end);
389 response.
SetHeader(headerName, headerValue);
394 namespace _internal {
396 struct HttpShared final
398 AZ_CORE_DLLEXPORT
static char const ContentType[];
399 AZ_CORE_DLLEXPORT
static char const ApplicationJson[];
400 AZ_CORE_DLLEXPORT
static char const Accept[];
401 AZ_CORE_DLLEXPORT
static char const MsRequestId[];
402 AZ_CORE_DLLEXPORT
static char const MsClientRequestId[];
404 static inline std::string GetHeaderOrEmptyString(
406 std::string
const& headerName)
408 auto header = headers.find(headerName);
409 if (header != headers.end())
411 return header->second;
434 static std::string GenerateUserAgent(
435 std::string
const& componentName,
436 std::string
const& componentVersion,
437 std::string
const& applicationId,
438 long cplusplusValue);
441 HttpShared() =
delete;
442 ~HttpShared() =
delete;
#define AZURE_ASSERT_MSG(exp, msg)
Azure specific assert macro with message.
Definition azure_assert.hpp:53
BodyStream is used to read data to/from a service.
A map<string, string> with case-insensitive key comparison.
std::map< std::string, std::string, _internal::StringExtensions::CaseInsensitiveComparator > CaseInsensitiveMap
A type alias of std::map<std::string, std::string> with case-insensitive key comparison.
Definition case_insensitive_containers.hpp:24
The method to be performed on the resource identified by the Request.
Definition http.hpp:94
HttpMethod(std::string value)
Constructs HttpMethod from string.
Definition http.hpp:103
AZ_CORE_DLLEXPORT static const HttpMethod Patch
The representation of a PATCH HTTP method based on [RFC 5789] (https://datatracker....
Definition http.hpp:160
AZ_CORE_DLLEXPORT static const HttpMethod Delete
The representation of a DELETE HTTP method based on [RFC 7231] (https://datatracker....
Definition http.hpp:154
AZ_CORE_DLLEXPORT static const HttpMethod Head
The representation of a HEAD HTTP method based on [RFC 7231] (https://datatracker....
Definition http.hpp:136
const std::string & ToString() const
Returns the HttpMethod represented as a string.
Definition http.hpp:124
bool operator==(const HttpMethod &other) const
Compares two instances of HttpMethod for equality.
Definition http.hpp:111
bool operator!=(const HttpMethod &other) const
Compares two instances of HttpMethod for equality.
Definition http.hpp:119
AZ_CORE_DLLEXPORT static const HttpMethod Put
The representation of a PUT HTTP method based on [RFC 7231] (https://datatracker.ietf....
Definition http.hpp:148
AZ_CORE_DLLEXPORT static const HttpMethod Post
The representation of a POST HTTP method based on [RFC 7231] (https://datatracker....
Definition http.hpp:142
AZ_CORE_DLLEXPORT static const HttpMethod Options
The representation of an OPTIONS HTTP method based on [RFC 2616] (https://datatracker....
Definition http.hpp:166
AZ_CORE_DLLEXPORT static const HttpMethod Get
The representation of a GET HTTP method based on [RFC 7231] (https://datatracker.ietf....
Definition http.hpp:130
After receiving and interpreting a request message, a server responds with an HTTP response message.
Definition raw_response.hpp:24
void SetHeader(std::string const &name, std::string const &value)
Set an HTTP header to the Azure::Core::Http::RawResponse.
Definition raw_response.cpp:17
A request message from a client to a server.
Definition http.hpp:182
Url const & GetUrl() const
Get URL.
Definition http.hpp:342
Request(HttpMethod httpMethod, Url url, Azure::Core::IO::BodyStream *bodyStream)
Constructs a Request.
Definition http.hpp:246
Azure::Core::IO::BodyStream const * GetBodyStream() const
Get HTTP body as Azure::Core::IO::BodyStream.
Definition http.hpp:324
Url & GetUrl()
Get URL.
Definition http.hpp:336
Azure::Nullable< std::string > GetHeader(std::string const &name)
Gets a specific HTTP header from an Azure::Core::Http::Request.
Definition request.cpp:38
HttpMethod const & GetMethod() const
Get HttpMethod.
Definition request.cpp:79
CaseInsensitiveMap GetHeaders() const
Get HTTP headers.
Definition request.cpp:81
void RemoveHeader(std::string const &name)
Remove an HTTP header.
Definition request.cpp:60
bool ShouldBufferResponse()
A value indicating whether the returned raw response for this request will be buffered within a memor...
Definition http.hpp:330
Azure::Core::IO::BodyStream * GetBodyStream()
Get HTTP body as Azure::Core::IO::BodyStream.
Definition http.hpp:318
Request(HttpMethod httpMethod, Url url, Azure::Core::IO::BodyStream *bodyStream, bool shouldBufferResponse)
Construct an Azure::Core::Http::Request.
Definition http.hpp:228
void SetHeader(std::string const &name, std::string const &value)
Set an HTTP header to the Azure::Core::Http::Request.
Definition request.cpp:52
An error while sending the HTTP request with the transport adapter.
Definition http.hpp:56
TransportException(std::string const &what)
Constructs TransportException with a message string.
Definition http.hpp:66
Used to read data to/from a service.
Definition body_stream.hpp:32
An error while trying to send a request to Azure service.
Definition exception.hpp:57
Represents the location where a request will be performed.
Definition url.hpp:46
Manages an optional contained value, i.e. a value that may or may not be present.
Definition nullable.hpp:30
Define RequestFailedException. It is used by HTTP exceptions.
HTTP status code definition.
Compute the hash value for the input binary data, using SHA256, SHA384 and SHA512.
Definition azure_assert.hpp:57
Manages an optional contained value, i.e. a value that may or may not be present.
Define the HTTP raw response.
The range of bytes within an HTTP resource.
Definition http.hpp:77
Azure::Nullable< int64_t > Length
The size of the HTTP Range.
Definition http.hpp:88
int64_t Offset
The starting point of the HTTP Range.
Definition http.hpp:82
Uniform Resource Locator (URL).