AWSEndpoint.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/core/endpoint/AWSEndpoint.h>
  6. #include <aws/core/utils/DNS.h>
  7. namespace Aws
  8. {
  9. namespace Endpoint
  10. {
  11. Aws::String AWSEndpoint::GetURL() const
  12. {
  13. return m_uri.GetURIString();
  14. }
  15. void AWSEndpoint::SetURL(Aws::String url)
  16. {
  17. m_uri = std::move(url);
  18. }
  19. const Aws::Http::URI& AWSEndpoint::GetURI() const
  20. {
  21. return m_uri;
  22. }
  23. void AWSEndpoint::SetURI(Aws::Http::URI uri)
  24. {
  25. m_uri = std::move(uri);
  26. }
  27. AWSEndpoint::OptionalError AWSEndpoint::AddPrefixIfMissing(const Aws::String& prefix)
  28. {
  29. if (m_uri.GetAuthority().rfind(prefix, 0) == 0)
  30. {
  31. // uri already starts with a prefix
  32. return OptionalError();
  33. }
  34. if (Aws::Utils::IsValidHost(prefix + m_uri.GetAuthority()))
  35. {
  36. m_uri.SetAuthority(prefix + m_uri.GetAuthority());
  37. return OptionalError();
  38. }
  39. return OptionalError(
  40. Aws::Client::AWSError<Aws::Client::CoreErrors>(
  41. Aws::Client::CoreErrors::ENDPOINT_RESOLUTION_FAILURE, "",
  42. Aws::String("Failed to add host prefix, resulting uri is an invalid hostname: ") + prefix + m_uri.GetAuthority(),
  43. false/*retryable*/));
  44. }
  45. void AWSEndpoint::SetQueryString(const Aws::String& queryString)
  46. {
  47. m_uri.SetQueryString(queryString);
  48. }
  49. const Crt::Optional<AWSEndpoint::EndpointAttributes>& AWSEndpoint::GetAttributes() const
  50. {
  51. return m_attributes;
  52. }
  53. Crt::Optional<AWSEndpoint::EndpointAttributes>& AWSEndpoint::AccessAttributes()
  54. {
  55. return m_attributes;
  56. }
  57. void AWSEndpoint::SetAttributes(AWSEndpoint::EndpointAttributes&& attributes)
  58. {
  59. m_attributes = std::move(attributes);
  60. }
  61. const Aws::UnorderedMap<Aws::String, Aws::String>& AWSEndpoint::GetHeaders() const
  62. {
  63. return m_headers;
  64. }
  65. void AWSEndpoint::SetHeaders(Aws::UnorderedMap<Aws::String, Aws::String> headers)
  66. {
  67. m_headers = std::move(headers);
  68. }
  69. } // namespace Endpoint
  70. } // namespace Aws