New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST Module Treats Header Names Case-Sensitively #3516

Closed
adrian-enspired opened this Issue Sep 15, 2016 · 0 comments

Comments

Projects
None yet
2 participants
@adrian-enspired
Contributor

adrian-enspired commented Sep 15, 2016

When encoding parameters, the REST module compares HTTP headers in a case-sensitive manner, which can prevent parameters from being encoded/sent with the request in some circumstances (e.g., when sending params as json).

https://github.com/Codeception/Codeception/blob/2.2/src/Codeception/Module/REST.php#L518-L520

RFC 2616 specifies that HTTP header names are case-insensitive.

4.2 Message Headers
HTTP header fields, which include general-header (section 4.5),
request-header (section 5.3), response-header (section 6.2), and
entity-header (section 7.1) fields, follow the same generic format as
that given in Section 3.1 of RFC 822 [9]. Each header field consists
of a name followed by a colon (":") and the field value. Field names
are case-insensitive.
[emphasis added]
https://www.ietf.org/rfc/rfc2616.txt

Steps to reproduce:

Test Subject:

<?php

$request_body = file_get_contents('php://input');

echo 'request body length: ', strlen($request_body), "\n",
  "request body contents: \n", $request_body, "\n--end--\n";

Test:

<?php
$I = new AcceptanceTester($scenario);

$params = ['foo' => 'foo', 'bar' => 'bar'];


$I->haveHttpHeader('Content-type', 'application/json');
$I->sendPost('/test_subject.php', $params);
echo  "case-insensitive:\n", $I->grabResponse();


$I->haveHttpHeader('Content-Type', 'application/json');
$I->sendPost('/test_subject.php', $params);
echo "\ncase-sensitive:\n", $I->grabResponse();

Expected Results:

Because http headers are case-insensitive, both headers should be seen as the same header, and therefore, both requests should be identical and should result in identical responses.

Actual Results:

The first request (which sets the header as "Content-type"; note capitalization) fails to encode and send the parameters with the request.

Codeception PHP Testing Framework v2.2.3
Powered by PHPUnit 5.4.8 by Sebastian Bergmann and contributors.

Acceptance Tests (1) ----------------------------------------------------------------
- codeCept: 
request body length: 0
request body contents: 

--end--

request body length: 25
request body contents: 
{"foo":"foo","bar":"bar"}
--end--
✔ codeCept:  (0.07s)
------------------------------------------------------------------------------


Time: 290 ms, Memory: 30.00MB

OK (1 test, 0 assertions)

Details

  • Codeception version: 2.2.3
  • PHP Version: 7.0.8
  • Operating System: Debian
  • Installation type: Composer
  • Suite configuration:
class_name: AcceptanceTester
modules:
    enabled:
        - REST:
            url: https://localhost/demo
            depends: PhpBrowser

@Naktibalda Naktibalda added the REST label Sep 15, 2016

Naktibalda added a commit to Naktibalda/Codeception that referenced this issue Sep 16, 2016

@Naktibalda Naktibalda closed this in #3526 Sep 18, 2016

chris1312 added a commit to chris1312/Codeception that referenced this issue Jun 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment