Scheme.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/core/http/Scheme.h>
  6. #include <aws/core/utils/memory/stl/AWSString.h>
  7. #include <aws/core/utils/StringUtils.h>
  8. using namespace Aws::Http;
  9. using namespace Aws::Utils;
  10. namespace Aws
  11. {
  12. namespace Http
  13. {
  14. namespace SchemeMapper
  15. {
  16. const char* ToString(Scheme scheme)
  17. {
  18. switch (scheme)
  19. {
  20. case Scheme::HTTP:
  21. return "http";
  22. case Scheme::HTTPS:
  23. return "https";
  24. default:
  25. return "http";
  26. }
  27. }
  28. Scheme FromString(const char* name)
  29. {
  30. Aws::String trimmedString = StringUtils::Trim(name);
  31. Aws::String loweredTrimmedString = StringUtils::ToLower(trimmedString.c_str());
  32. if (loweredTrimmedString == "http")
  33. {
  34. return Scheme::HTTP;
  35. }
  36. //this branch is technically unneeded, but it is here so we don't have a subtle bug
  37. //creep in as we extend this enum.
  38. else if (loweredTrimmedString == "https")
  39. {
  40. return Scheme::HTTPS;
  41. }
  42. return Scheme::HTTPS;
  43. }
  44. } // namespace SchemeMapper
  45. } // namespace Http
  46. } // namespace Aws