|
17 | 17 |
|
18 | 18 | import java.net.URI;
|
19 | 19 | import java.net.URISyntaxException;
|
| 20 | +import java.nio.charset.Charset; |
20 | 21 | import java.util.concurrent.CountDownLatch;
|
21 | 22 | import java.util.concurrent.TimeUnit;
|
22 | 23 |
|
@@ -225,4 +226,35 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
|
225 | 226 | Assert.assertTrue(!"".equals(info.reqId));
|
226 | 227 | Assert.assertEquals(400, info.statusCode);
|
227 | 228 | }
|
| 229 | + |
| 230 | + @SmallTest |
| 231 | + public void testHeader() { |
| 232 | + // com.qiniu.android.http.UserAgent#getUa |
| 233 | + // return new String((ua + "; " + _part + ")").getBytes(Charset.forName("ISO-8859-1"))); |
| 234 | + |
| 235 | + String name = new String(("电话☎️的の").getBytes(Charset.forName("ISO-8859-1"))); |
| 236 | + String value = new String(("sdf✈️he覆盖😁🆚9837-=/ df").getBytes(Charset.forName("ISO-8859-1"))); |
| 237 | + checkNameAndValue(name, value); |
| 238 | + } |
| 239 | + |
| 240 | + // copy from okhttp3.Headers |
| 241 | + private void checkNameAndValue(String name, String value) { |
| 242 | + if (name == null) throw new IllegalArgumentException("name == null"); |
| 243 | + if (name.isEmpty()) throw new IllegalArgumentException("name is empty"); |
| 244 | + for (int i = 0, length = name.length(); i < length; i++) { |
| 245 | + char c = name.charAt(i); |
| 246 | + if (c <= '\u001f' || c >= '\u007f') { |
| 247 | + throw new IllegalArgumentException(String.format( |
| 248 | + "Unexpected char %#04x at %d in header name: %s", (int) c, i, name)); |
| 249 | + } |
| 250 | + } |
| 251 | + if (value == null) throw new IllegalArgumentException("value == null"); |
| 252 | + for (int i = 0, length = value.length(); i < length; i++) { |
| 253 | + char c = value.charAt(i); |
| 254 | + if (c <= '\u001f' || c >= '\u007f') { |
| 255 | + throw new IllegalArgumentException(String.format( |
| 256 | + "Unexpected char %#04x at %d in %s value: %s", (int) c, i, name, value)); |
| 257 | + } |
| 258 | + } |
| 259 | + } |
228 | 260 | }
|
0 commit comments