Last active
March 22, 2016 01:44
-
-
Save noodlehaus/e2d00d631ee95173a082 to your computer and use it in GitHub Desktop.
header flushing code from zend-diactoros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
array_walk($headers, function ($value, $key) { | |
# validate header key (ref: zend-diactoros) | |
if (! preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/', $key)) { | |
throw new InvalidArgumentException("Invalid header name - {$key}"); | |
} | |
# validate header values (ref: zend-diactoros) | |
$values = is_array($value) ? $value : [$value]; | |
foreach ($values as $val) { | |
if ( | |
preg_match("#(?:(?:(?<!\r)\n)|(?:\r(?!\n))|(?:\r\n(?![ \t])))#", $val) || | |
preg_match('/[^\x09\x0a\x0d\x20-\x7E\x80-\xFE]/', $val) | |
) { | |
throw new InvalidArgumentException("Invalid header value - {$val}"); | |
} | |
} | |
header($key.': '.implode(',', $values)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment