| @@ 650-688 (lines=39) @@ | ||
| 647 | * |
|
| 648 | * @return array |
|
| 649 | */ |
|
| 650 | public static function http_parse_headers($raw_headers) |
|
| 651 | { |
|
| 652 | $headers = []; |
|
| 653 | $key = ''; // [+] |
|
| 654 | ||
| 655 | foreach (explode("\n", $raw_headers) as $i => $h) { |
|
| 656 | $h = explode(':', $h, 2); |
|
| 657 | ||
| 658 | if (isset($h[1])) { |
|
| 659 | if (!isset($headers[$h[0]])) { |
|
| 660 | $headers[$h[0]] = trim($h[1]); |
|
| 661 | } elseif (is_array($headers[$h[0]])) { |
|
| 662 | // $tmp = array_merge($headers[$h[0]], array(trim($h[1]))); // [-] |
|
| 663 | // $headers[$h[0]] = $tmp; // [-] |
|
| 664 | $headers[$h[0]] = array_merge($headers[$h[0]], [trim($h[1])]); // [+] |
|
| 665 | } else { |
|
| 666 | // $tmp = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [-] |
|
| 667 | // $headers[$h[0]] = $tmp; // [-] |
|
| 668 | $headers[$h[0]] = array_merge([$headers[$h[0]]], [trim($h[1])]); // [+] |
|
| 669 | } |
|
| 670 | ||
| 671 | $key = $h[0]; // [+] |
|
| 672 | } else { |
|
| 673 | // [+] |
|
| 674 | // [+] |
|
| 675 | if (substr($h[0], 0, 1) == "\t") { |
|
| 676 | // [+] |
|
| 677 | $headers[$key] .= "\r\n\t" . trim($h[0]); |
|
| 678 | } // [+] |
|
| 679 | elseif (!$key) { |
|
| 680 | // [+] |
|
| 681 | $headers[0] = trim($h[0]); |
|
| 682 | } |
|
| 683 | trim($h[0]); // [+] |
|
| 684 | } // [+] |
|
| 685 | } |
|
| 686 | ||
| 687 | return $headers; |
|
| 688 | } |
|
| 689 | ||
| 690 | /** |
|
| 691 | * 缓存方法 |
|
| @@ 536-574 (lines=39) @@ | ||
| 533 | * |
|
| 534 | * @return array |
|
| 535 | */ |
|
| 536 | public static function http_parse_headers($raw_headers) |
|
| 537 | {
|
|
| 538 | $headers = []; |
|
| 539 | $key = ''; // [+] |
|
| 540 | ||
| 541 | foreach (explode("\n", $raw_headers) as $i => $h) {
|
|
| 542 | $h = explode(':', $h, 2);
|
|
| 543 | ||
| 544 | if (isset($h[1])) {
|
|
| 545 | if (!isset($headers[$h[0]])) {
|
|
| 546 | $headers[$h[0]] = trim($h[1]); |
|
| 547 | } elseif (is_array($headers[$h[0]])) {
|
|
| 548 | // $tmp = array_merge($headers[$h[0]], array(trim($h[1]))); // [-] |
|
| 549 | // $headers[$h[0]] = $tmp; // [-] |
|
| 550 | $headers[$h[0]] = array_merge($headers[$h[0]], [trim($h[1])]); // [+] |
|
| 551 | } else {
|
|
| 552 | // $tmp = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [-] |
|
| 553 | // $headers[$h[0]] = $tmp; // [-] |
|
| 554 | $headers[$h[0]] = array_merge([$headers[$h[0]]], [trim($h[1])]); // [+] |
|
| 555 | } |
|
| 556 | ||
| 557 | $key = $h[0]; // [+] |
|
| 558 | } else {
|
|
| 559 | // [+] |
|
| 560 | // [+] |
|
| 561 | if (substr($h[0], 0, 1) == "\t") {
|
|
| 562 | // [+] |
|
| 563 | $headers[$key] .= "\r\n\t" . trim($h[0]); |
|
| 564 | } // [+] |
|
| 565 | elseif (!$key) {
|
|
| 566 | // [+] |
|
| 567 | $headers[0] = trim($h[0]); |
|
| 568 | } |
|
| 569 | trim($h[0]); // [+] |
|
| 570 | } // [+] |
|
| 571 | } |
|
| 572 | ||
| 573 | return $headers; |
|
| 574 | } |
|
| 575 | ||
| 576 | /** |
|
| 577 | * 缓存方法 |
|