azure-data-tables
Loading...
Searching...
No Matches
url_encode.hpp
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
6#include <memory>
7#include <stdexcept>
8#include <stdint.h>
9#include <string>
10#include <vector>
11
12namespace Azure { namespace Data { namespace Tables { namespace _detail { namespace Cryptography {
13
14 class UrlUtils final {
15 public:
16 static std::string UrlEncodeQueryParameter(const std::string& value)
17 {
18 const static std::string DoNotEncodeCharacters = []() {
19 // Core::Url::Encode won't encode unreserved characters.
20 std::string doNotEncodeCharacters = "!$&'()*+,;=";
21 doNotEncodeCharacters += "/:@?";
22 doNotEncodeCharacters.erase(
23 std::remove_if(
24 doNotEncodeCharacters.begin(),
25 doNotEncodeCharacters.end(),
26 [](char x) {
27 // we also encode + and &
28 // Surprisingly, '=' also needs to be encoded because Azure Storage server side is
29 // so strict. We are applying this function to query key and value respectively,
30 // so this won't affect that = used to separate key and query.
31 return x == '+' || x == '=' || x == '&';
32 }),
33 doNotEncodeCharacters.end());
34 return doNotEncodeCharacters;
35 }();
36 return Core::Url::Encode(value, DoNotEncodeCharacters);
37 }
38
39 static std::string UrlEncodePath(const std::string& value)
40 {
41 const static std::string DoNotEncodeCharacters = []() {
42 // Core::Url::Encode won't encode unreserved characters.
43 std::string doNotEncodeCharacters = "!$&'()*+,;=";
44 doNotEncodeCharacters += "/:@";
45 doNotEncodeCharacters.erase(
46 std::remove_if(
47 doNotEncodeCharacters.begin(),
48 doNotEncodeCharacters.end(),
49 [](char x) {
50 // we also encode +
51 return x == '+';
52 }),
53 doNotEncodeCharacters.end());
54 return doNotEncodeCharacters;
55 }();
56 return Core::Url::Encode(value, DoNotEncodeCharacters);
57 }
58 };
59}}}}} // namespace Azure::Data::Tables::_detail::Cryptography