|
33 | 33 | import java.nio.charset.StandardCharsets; |
34 | 34 | import java.util.BitSet; |
35 | 35 |
|
| 36 | +import org.apache.hc.core5.annotation.Internal; |
| 37 | + |
36 | 38 | /** |
37 | 39 | * Percent-encoding. |
38 | 40 | * |
@@ -113,6 +115,36 @@ public class PercentCodec { |
113 | 115 | RFC5987_UNRESERVED.set('~'); |
114 | 116 | } |
115 | 117 |
|
| 118 | + static final BitSet HTTP_TOKEN_UNRESERVED = new BitSet(256); |
| 119 | + |
| 120 | + static { |
| 121 | + // HTTP token characters (tchar) minus '%' (percent-encoded per RFC 7639 canonical form) |
| 122 | + for (int i = 'a'; i <= 'z'; i++) { |
| 123 | + HTTP_TOKEN_UNRESERVED.set(i); |
| 124 | + } |
| 125 | + for (int i = 'A'; i <= 'Z'; i++) { |
| 126 | + HTTP_TOKEN_UNRESERVED.set(i); |
| 127 | + } |
| 128 | + for (int i = '0'; i <= '9'; i++) { |
| 129 | + HTTP_TOKEN_UNRESERVED.set(i); |
| 130 | + } |
| 131 | + |
| 132 | + HTTP_TOKEN_UNRESERVED.set('!'); |
| 133 | + HTTP_TOKEN_UNRESERVED.set('#'); |
| 134 | + HTTP_TOKEN_UNRESERVED.set('$'); |
| 135 | + HTTP_TOKEN_UNRESERVED.set('&'); |
| 136 | + HTTP_TOKEN_UNRESERVED.set('\''); |
| 137 | + HTTP_TOKEN_UNRESERVED.set('*'); |
| 138 | + HTTP_TOKEN_UNRESERVED.set('+'); |
| 139 | + HTTP_TOKEN_UNRESERVED.set('-'); |
| 140 | + HTTP_TOKEN_UNRESERVED.set('.'); |
| 141 | + HTTP_TOKEN_UNRESERVED.set('^'); |
| 142 | + HTTP_TOKEN_UNRESERVED.set('_'); |
| 143 | + HTTP_TOKEN_UNRESERVED.set('`'); |
| 144 | + HTTP_TOKEN_UNRESERVED.set('|'); |
| 145 | + HTTP_TOKEN_UNRESERVED.set('~'); |
| 146 | + } |
| 147 | + |
116 | 148 | static final BitSet PCHAR = new BitSet(256); |
117 | 149 | static final BitSet USERINFO = new BitSet(256); |
118 | 150 | static final BitSet REG_NAME = new BitSet(256); |
@@ -217,10 +249,12 @@ public static String decode(final CharSequence content, final Charset charset) { |
217 | 249 |
|
218 | 250 | public static final PercentCodec RFC3986 = new PercentCodec(UNRESERVED); |
219 | 251 | public static final PercentCodec RFC5987 = new PercentCodec(RFC5987_UNRESERVED); |
| 252 | + public static final PercentCodec HTTP_TOKEN = new PercentCodec(HTTP_TOKEN_UNRESERVED); |
220 | 253 |
|
221 | 254 | private final BitSet unreserved; |
222 | 255 |
|
223 | | - private PercentCodec(final BitSet unreserved) { |
| 256 | + @Internal |
| 257 | + public PercentCodec(final BitSet unreserved) { |
224 | 258 | this.unreserved = unreserved; |
225 | 259 | } |
226 | 260 |
|
|
0 commit comments