Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,92 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include "HttpTypes.h"
namespace HttpRequestor
{
/*
**
** The Parameters needed to make a HTTP call and then receive the
** returned JSON in a meaningful place. Examples of use are in the
** HttpRequestCaller class.
**
*/
class Parameters
{
public:
// Initializing ctor
Parameters(const AZStd::string& URI, Aws::Http::HttpMethod method, const Callback& callback);
Parameters(const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers& headers, const Callback& callback);
Parameters(const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers& headers, const AZStd::string& body, const Callback& callback);
// Defaults
virtual ~Parameters() = default;
Parameters(const Parameters&) = default;
Parameters& operator=(const Parameters&) = default;
Parameters(Parameters&&) = default;
Parameters& operator=(Parameters&&) = default;
//returns the URI in string form as an recipient of the HTTP connection
const Aws::String& GetURI() const { return m_URI; }
//returns the method of which the HTTP request will take. GET, POST, DELETE, PUT, or HEAD
Aws::Http::HttpMethod GetMethod() const { return m_method; }
//returns the list of extra headers to include in the request
const Headers & GetHeaders() const { return m_headers; }
//returns the stream for the body of the request
const std::shared_ptr<std::stringstream> & GetBodyStream() const { return m_bodyStream; }
//returns the function of which to feed back the JSON that the HTTP call resulted in. The function also requires the HTTPResponseCode indicating if the call was successful or failed
const Callback & GetCallback() const { return m_callback; }
private:
Aws::String m_URI;
Aws::Http::HttpMethod m_method;
Headers m_headers;
std::shared_ptr<std::stringstream> m_bodyStream; // required by Aws::Http::HttpRequest
Callback m_callback;
};
inline Parameters::Parameters(const AZStd::string& URI, Aws::Http::HttpMethod method, const Callback& callback)
: m_URI(URI.c_str())
, m_method(method)
, m_callback(callback)
{
}
inline Parameters::Parameters(const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers& headers, const Callback& callback)
: m_URI(URI.c_str())
, m_method(method)
, m_headers(headers)
, m_callback(callback)
{
}
inline Parameters::Parameters(const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers& headers, const AZStd::string& body, const Callback& callback)
: m_URI(URI.c_str())
, m_method(method)
, m_headers(headers)
, m_bodyStream(std::make_shared<std::stringstream>(body.c_str()))
, m_callback(callback)
{
}
}
@@ -0,0 +1,40 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
#include "HttpTypes.h"
namespace HttpRequestor
{
class HttpRequestorRequests
: public AZ::EBusTraits
{
public:
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
// Public functions
virtual void AddRequest(const AZStd::string& URI, Aws::Http::HttpMethod method, const Callback& callback) = 0;
virtual void AddRequestWithHeaders(const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers & headers, const Callback& callback) = 0;
virtual void AddRequestWithHeadersAndBody(const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers & headers, const AZStd::string& body, const Callback& callback) = 0;
virtual void AddTextRequest(const AZStd::string& URI, Aws::Http::HttpMethod method, const TextCallback& callback) = 0;
virtual void AddTextRequestWithHeaders(const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers & headers, const TextCallback& callback) = 0;
virtual void AddTextRequestWithHeadersAndBody(const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers & headers, const AZStd::string& body, const TextCallback& callback) = 0;
};
using HttpRequestorRequestBus = AZ::EBus<HttpRequestorRequests>;
} // namespace HttpRequestor
@@ -0,0 +1,87 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "HttpTypes.h"
#include <sstream>
namespace HttpRequestor
{
/*
**
** The Parameters needed to make a HTTP call and then receive the
** returned TEXT from the web request without parsing it.
**
*/
class TextParameters
{
public:
// Initializing ctor
TextParameters(const AZStd::string& URI, Aws::Http::HttpMethod method, const TextCallback& callback);
TextParameters(const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers& headers, const TextCallback& callback);
TextParameters(const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers& headers, const AZStd::string& body, const TextCallback& callback);
// Defaults
~TextParameters() = default;
TextParameters(const TextParameters&) = default;
TextParameters& operator=(const TextParameters&) = default;
TextParameters(TextParameters&&) = default;
TextParameters& operator=(TextParameters&&) = default;
//returns the URI in string form as an recipient of the HTTP connection
const Aws::String& GetURI() const { return m_URI; }
//returns the method of which the HTTP request will take. GET, POST, DELETE, PUT, or HEAD
Aws::Http::HttpMethod GetMethod() const { return m_method; }
//returns the list of extra headers to include in the request
const Headers & GetHeaders() const { return m_headers; }
//returns the stream for the body of the request
const std::shared_ptr<std::stringstream> & GetBodyStream() const { return m_bodyStream; }
//returns the function of which to feed back the TEXT that the HTTP call resulted in. The function also requires the HTTPResponseCode indicating if the call was successful or failed
const TextCallback & GetCallback() const { return m_callback; }
private:
Aws::String m_URI;
Aws::Http::HttpMethod m_method;
Headers m_headers;
std::shared_ptr<std::stringstream> m_bodyStream;
TextCallback m_callback;
};
inline TextParameters::TextParameters(const AZStd::string& URI, Aws::Http::HttpMethod method, const TextCallback& callback)
: m_URI(URI.c_str())
, m_method(method)
, m_callback(callback)
{
}
inline TextParameters::TextParameters(const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers& headers, const TextCallback& callback)
: m_URI(URI.c_str())
, m_method(method)
, m_headers(headers)
, m_callback(callback)
{
}
inline TextParameters::TextParameters(const AZStd::string& URI, Aws::Http::HttpMethod method, const Headers& headers, const AZStd::string& body, const TextCallback& callback)
: m_URI(URI.c_str())
, m_method(method)
, m_headers(headers)
, m_bodyStream( std::make_shared<std::stringstream>(body.c_str()) )
, m_callback(callback)
{
}
}
@@ -0,0 +1,46 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
// The AWS Native SDK AWSAllocator triggers a warning due to accessing members of std::allocator directly.
// AWSAllocator.h(70): warning C4996: 'std::allocator<T>::pointer': warning STL4010: Various members of std::allocator are deprecated in C++17.
// Use std::allocator_traits instead of accessing these members directly.
// You can define _SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning.
AZ_PUSH_DISABLE_WARNING(4251 4996, "-Wunknown-warning-option")
#include <aws/core/http/HttpTypes.h>
#include <aws/core/http/HttpResponse.h>
#include <aws/core/utils/json/JsonSerializer.h>
AZ_POP_DISABLE_WARNING
#include <AzCore/std/string/string.h>
#include <AzCore/std/containers/map.h>
#include <AzCore/std/functional.h>
namespace HttpRequestor
{
//
// the call back function for http requests.
//
using Callback = AZStd::function<void(const Aws::Utils::Json::JsonView&, Aws::Http::HttpResponseCode)>;
//
// the call back function for any http text requests.
//
using TextCallback = AZStd::function<void(const AZStd::string&, Aws::Http::HttpResponseCode)>;
//
// a map of REST headers.
//
using Headers = AZStd::map<AZStd::string, AZStd::string>;
}