|
27 | 27 | #import "GSURLPrivate.h" |
28 | 28 | #import "GSPrivate.h" |
29 | 29 |
|
| 30 | +#import "Foundation/NSBundle.h" |
30 | 31 | #import "Foundation/NSCoder.h" |
31 | 32 | #import "Foundation/NSDictionary.h" |
32 | 33 | #import "Foundation/NSScanner.h" |
@@ -380,8 +381,141 @@ @implementation NSHTTPURLResponse |
380 | 381 |
|
381 | 382 | + (NSString *) localizedStringForStatusCode: (NSInteger)statusCode |
382 | 383 | { |
383 | | -// FIXME ... put real responses in here |
384 | | - return [NSString stringWithFormat: @"%"PRIdPTR, statusCode]; |
| 384 | + /* Mappings from codes to text taken from |
| 385 | + * https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
| 386 | + */ |
| 387 | + switch (statusCode) |
| 388 | + { |
| 389 | + case 100: |
| 390 | + return NSLocalizedString(@"Continue", @"HTTP Status"); |
| 391 | + case 101: |
| 392 | + return NSLocalizedString(@"Switching Protocols", @"HTTP Status"); |
| 393 | + case 102: |
| 394 | + return NSLocalizedString(@"Processing", @"HTTP Status"); |
| 395 | + case 103: |
| 396 | + return NSLocalizedString(@"Early Hints", @"HTTP Status"); |
| 397 | + case 200: |
| 398 | + return NSLocalizedString(@"OK", @"HTTP Status"); |
| 399 | + case 201: |
| 400 | + return NSLocalizedString(@"Created", @"HTTP Status"); |
| 401 | + case 202: |
| 402 | + return NSLocalizedString(@"Accepted", @"HTTP Status"); |
| 403 | + case 203: |
| 404 | + return NSLocalizedString(@"Non-Authoritative Information", |
| 405 | + @"HTTP Status"); |
| 406 | + case 204: |
| 407 | + return NSLocalizedString(@"No Content", @"HTTP Status"); |
| 408 | + case 205: |
| 409 | + return NSLocalizedString(@"Reset Content", @"HTTP Status"); |
| 410 | + case 206: |
| 411 | + return NSLocalizedString(@"Partial Content", @"HTTP Status"); |
| 412 | + case 207: |
| 413 | + return NSLocalizedString(@"Multi-Status", @"HTTP Status"); |
| 414 | + case 208: |
| 415 | + return NSLocalizedString(@"Already Reported", @"HTTP Status"); |
| 416 | + case 226: |
| 417 | + return NSLocalizedString(@"IM Used", @"HTTP Status"); |
| 418 | + case 300: |
| 419 | + return NSLocalizedString(@"Multiple Choices", @"HTTP Status"); |
| 420 | + case 301: |
| 421 | + return NSLocalizedString(@"Moved Permanently", @"HTTP Status"); |
| 422 | + case 302: |
| 423 | + return NSLocalizedString(@"Found", @"HTTP Status"); |
| 424 | + case 303: |
| 425 | + return NSLocalizedString(@"See Other", @"HTTP Status"); |
| 426 | + case 304: |
| 427 | + return NSLocalizedString(@"Not Modified", @"HTTP Status"); |
| 428 | + case 305: |
| 429 | + return NSLocalizedString(@"Use Proxy", @"HTTP Status"); |
| 430 | + case 307: |
| 431 | + return NSLocalizedString(@"Temporary Redirect", @"HTTP Status"); |
| 432 | + case 308: |
| 433 | + return NSLocalizedString(@"Permanent Redirect", @"HTTP Status"); |
| 434 | + case 400: |
| 435 | + return NSLocalizedString(@"Bad Request", @"HTTP Status"); |
| 436 | + case 401: |
| 437 | + return NSLocalizedString(@"Unauthorized", @"HTTP Status"); |
| 438 | + case 402: |
| 439 | + return NSLocalizedString(@"Payment Required", @"HTTP Status"); |
| 440 | + case 403: |
| 441 | + return NSLocalizedString(@"Forbidden", @"HTTP Status"); |
| 442 | + case 404: |
| 443 | + return NSLocalizedString(@"Not Found", @"HTTP Status"); |
| 444 | + case 405: |
| 445 | + return NSLocalizedString(@"Method Not Allowed", @"HTTP Status"); |
| 446 | + case 406: |
| 447 | + return NSLocalizedString(@"Not Acceptable", @"HTTP Status"); |
| 448 | + case 407: |
| 449 | + return NSLocalizedString(@"Proxy Authentication Required", |
| 450 | + @"HTTP Status"); |
| 451 | + case 408: |
| 452 | + return NSLocalizedString(@"Request Timeout", @"HTTP Status"); |
| 453 | + case 409: |
| 454 | + return NSLocalizedString(@"Conflict", @"HTTP Status"); |
| 455 | + case 410: |
| 456 | + return NSLocalizedString(@"Gone", @"HTTP Status"); |
| 457 | + case 411: |
| 458 | + return NSLocalizedString(@"Length Required", @"HTTP Status"); |
| 459 | + case 412: |
| 460 | + return NSLocalizedString(@"Precondition Failed", @"HTTP Status"); |
| 461 | + case 413: |
| 462 | + return NSLocalizedString(@"Content Too Large", @"HTTP Status"); |
| 463 | + case 414: |
| 464 | + return NSLocalizedString(@"URI Too Long", @"HTTP Status"); |
| 465 | + case 415: |
| 466 | + return NSLocalizedString(@"Unsupported Media Type", @"HTTP Status"); |
| 467 | + case 416: |
| 468 | + return NSLocalizedString(@"Range Not Satisfiable", @"HTTP Status"); |
| 469 | + case 417: |
| 470 | + return NSLocalizedString(@"Expectation Failed", @"HTTP Status"); |
| 471 | + case 421: |
| 472 | + return NSLocalizedString(@"Misdirected Request", @"HTTP Status"); |
| 473 | + case 422: |
| 474 | + return NSLocalizedString(@"Unprocessable Content", @"HTTP Status"); |
| 475 | + case 423: |
| 476 | + return NSLocalizedString(@"Locked", @"HTTP Status"); |
| 477 | + case 424: |
| 478 | + return NSLocalizedString(@"Failed Dependency", @"HTTP Status"); |
| 479 | + case 425: |
| 480 | + return NSLocalizedString(@"Too Early", @"HTTP Status"); |
| 481 | + case 426: |
| 482 | + return NSLocalizedString(@"Upgrade Required", @"HTTP Status"); |
| 483 | + case 428: |
| 484 | + return NSLocalizedString(@"Precondition Required", @"HTTP Status"); |
| 485 | + case 429: |
| 486 | + return NSLocalizedString(@"Too Many Requests", @"HTTP Status"); |
| 487 | + case 431: |
| 488 | + return NSLocalizedString(@"Request Header Fields Too Large", |
| 489 | + @"HTTP Status"); |
| 490 | + case 451: |
| 491 | + return NSLocalizedString(@"Unavailable For Legal Reasons", |
| 492 | + @"HTTP Status"); |
| 493 | + case 500: |
| 494 | + return NSLocalizedString(@"Internal Server Error", @"HTTP Status"); |
| 495 | + case 501: |
| 496 | + return NSLocalizedString(@"Not Implemented", @"HTTP Status"); |
| 497 | + case 502: |
| 498 | + return NSLocalizedString(@"Bad Gateway", @"HTTP Status"); |
| 499 | + case 503: |
| 500 | + return NSLocalizedString(@"Service Unavailable", @"HTTP Status"); |
| 501 | + case 504: |
| 502 | + return NSLocalizedString(@"Gateway Timeout", @"HTTP Status"); |
| 503 | + case 505: |
| 504 | + return NSLocalizedString(@"HTTP Version Not Supported", @"HTTP Status"); |
| 505 | + case 506: |
| 506 | + return NSLocalizedString(@"Variant Also Negotiates", @"HTTP Status"); |
| 507 | + case 507: |
| 508 | + return NSLocalizedString(@"Insufficient Storage", @"HTTP Status"); |
| 509 | + case 508: |
| 510 | + return NSLocalizedString(@"Loop Detected", @"HTTP Status"); |
| 511 | + case 510: |
| 512 | + return NSLocalizedString(@"Not Extended (OBSOLETED)", @"HTTP Status"); |
| 513 | + case 511: |
| 514 | + return NSLocalizedString(@"Network Authentication Required", |
| 515 | + @"HTTP Status"); |
| 516 | + default: |
| 517 | + return [NSString stringWithFormat: @"%"PRIdPTR, statusCode]; |
| 518 | + } |
385 | 519 | } |
386 | 520 |
|
387 | 521 | - (NSDictionary *) allHeaderFields |
|
0 commit comments