| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright 2016 gRPC authors. |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef GRPC_CORE_LIB_SLICE_PERCENT_ENCODING_H |
| 20 |
#define GRPC_CORE_LIB_SLICE_PERCENT_ENCODING_H |
| 21 |
|
| 22 |
/* Percent encoding and decoding of slices. |
| 23 |
Transforms arbitrary strings into safe-for-transmission strings by using |
| 24 |
variants of percent encoding (RFC 3986). |
| 25 |
Two major variants are supplied: one that strictly matches URL encoding, |
| 26 |
and another which applies percent encoding only to non-http2 header |
| 27 |
bytes (the 'compatible' variant) */ |
| 28 |
|
| 29 |
#include <grpc/support/port_platform.h> |
| 30 |
|
| 31 |
#include "src/core/lib/slice/slice.h" |
| 32 |
|
| 33 |
namespace grpc_core { |
| 34 |
|
| 35 |
enum class PercentEncodingType { |
| 36 |
// Flags [A-Za-z0-9-_.~] as unreserved bytes for the percent encoding routines |
| 37 |
URL, |
| 38 |
// Flags ascii7 non-control characters excluding '%' as unreserved bytes for |
| 39 |
// the percent encoding routines |
| 40 |
Compatible |
| 41 |
}; |
| 42 |
|
| 43 |
// Percent-encode a slice, returning the new slice (this cannot fail): |
| 44 |
// unreserved_bytes is a bitfield indicating which bytes are considered |
| 45 |
// unreserved and thus do not need percent encoding |
| 46 |
Slice PercentEncodeSlice(Slice slice, PercentEncodingType type); |
| 47 |
// Percent-decode a slice, permissively. |
| 48 |
// If a % triplet can not be decoded, pass it through verbatim. |
| 49 |
// This cannot fail. |
| 50 |
Slice PermissivePercentDecodeSlice(Slice slice_in); |
| 51 |
|
| 52 |
} // namespace grpc_core |
| 53 |
|
| 54 |
#endif /* GRPC_CORE_LIB_SLICE_PERCENT_ENCODING_H */ |