8000 minor #22357 [HttpFoundation] Fix and test status codes according to … · symfony/symfony@6928f12 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6928f12

Browse files
committed
minor #22357 [HttpFoundation] Fix and test status codes according to IANA's data (dunglas)
This PR was merged into the 2.7 branch. Discussion ---------- [HttpFoundation] Fix and test status codes according to IANA's data | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a This PR updates HTTP status code according to values [standardized by the IANA](https://www.iana.org/assignments/http-status-codes/http-status-codes.xml). It also add a test to check the conformance (we'll also be notified when a code is added, ~~removed~~ or modified). All credits go to @fcabralpacheco for is work in Zend Diactoros: zendframework/zend-diactoros#234 Commits ------- 72d25cc [HttpFoundation] Fix and test status codes according to IANA's data
2 parents 34655e6 + 72d25cc commit 6928f12

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ class Response
158158
410 => 'Gone',
159159
411 => 'Length Required',
160160
412 => 'Precondition Failed',
161-
413 => 'Request Entity Too Large',
162-
414 => 'Request-URI Too Long',
161+
413 => 'Payload Too Large',
162+
414 => 'URI Too Long',
163163
415 => 'Unsupported Media Type',
164-
416 => 'Requested Range Not Satisfiable',
164+
416 => 'Range Not Satisfiable',
165165
417 => 'Expectation Failed',
166166
418 => 'I\'m a teapot', // RFC2324
167167
421 => 'Misdirected Request', // RFC7540
@@ -180,7 +180,7 @@ class Response
180180
503 => 'Service Unavailable',
181181
504 => 'Gateway Timeout',
182182
505 => 'HTTP Version Not Supported',
183-
506 => 'Variant Also Negotiates (Experimental)', // RFC2295
183+
506 => 'Variant Also Negotiates', // RFC2295
184184
507 => 'Insufficient Storage', // RFC4918
185185
508 => 'Loop Detected', // RFC5842
186186
510 => 'Not Extended', // RFC2774

src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,67 @@ protected function provideResponse()
882882
{
883883
return new Response();
884884
}
885+
886+
/**
887+
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
888+
*
889+
* @author Fábio Pacheco
890+
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
891+
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
892+
*/
893+
public function ianaCodesReasonPhrasesProvider()
894+
{
895+
if (!in_array('https', stream_get_wrappers(), true)) {
896+
$this->markTestSkipped('The "https" wrapper is not available');
897+
}
898+
899+
$ianaHttpStatusCodes = new \DOMDocument();
900+
901+
libxml_set_streams_context(stream_context_create(array(
902+
'http' => array(
903+
'method' => 'GET',
904+
'timeout' => 30,
905+
),
906+
)));
907+
908+
$ianaHttpStatusCodes->load('https://www.iana.org/assignments/http-status-codes/http-status-codes.xml');
909+
if (!$ianaHttpStatusCodes->relaxNGValidate('https://www.iana.org/assignments/http-status-codes/http-status-codes.rng')) {
910+
self::fail('Invalid IANA\'s HTTP status code list.');
911+
}
912+
913+
$ianaCodesReasonPhrases = array();
914+
915+
$xpath = new \DomXPath($ianaHttpStatusCodes);
916+
$xpath->registerNamespace('ns', 'http://www.iana.org/assignments');
917+
918+
$records = $xpath->query('//ns:record');
919+
foreach ($records as $record) {
920+
$value = $xpath->query('.//ns:value', $record)->item(0)->nodeValue;
921+
$description = $xpath->query('.//ns:description', $record)->item(0)->nodeValue;
922+
923+
if (in_array($description, array('Unassigned', '(Unused)'), true)) {
924+
continue;
925+
}
926+
927+
if (preg_match('/^([0-9]+)\s*\-\s*([0-9]+)$/', $value, $matches)) {
928+
for ($value = $matches[1]; $value <= $matches[2]; ++$value) {
929+
$ianaCodesReasonPhrases[] = array($value, $description);
930+
}
931+
} else {
932+
$ianaCodesReasonPhrases[] = array($value, $description);
933+
}
934+
}
935+
936+
return $ianaCodesReasonPhrases;
937+
}
938+
939+
/**
940+
* @dataProvider ianaCodesReasonPhrasesProvider
941+
*/
942+
public function testReasonPhraseDefaultsAgainstIana($code, $reasonPhrase)
943+
{
944+
$this->assertEquals($reasonPhrase, Response::$statusTexts[$code]);
945+
}
885946
}
886947

887948
class StringableObject

0 commit comments

Comments
 (0)
0