Skip to content
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

Content-Type shouldn't be sent with HTTP 204? #501

Closed
shaneneuerburg opened this issue Nov 15, 2015 · 1 comment
Closed

Content-Type shouldn't be sent with HTTP 204? #501

shaneneuerburg opened this issue Nov 15, 2015 · 1 comment

Comments

@shaneneuerburg
Copy link
Contributor

Another library, Siesta for iOS, expects an HTTP 204 to not include the Content-Type (or, I should say that if that is present, they try to parse the non-existent body).

The RFC states the following:

Any HTTP/1.1 message containing an entity-body SHOULD include a
Content-Type header field defining the media type of that body.

While it doesn't explicitly state that the header shouldn't be sent if there is no body, it only states that it should if the body exists.

I'd suggest moving the Content-Type generation logic after the status code assignment, with it wrapped in a conditional where $code != 204.

Thoughts?

@Arul- Arul- self-assigned this Nov 18, 2015
@Arul-
Copy link
Member

Arul- commented Nov 29, 2015

While we think about the long term solution for this problem, you can easily implement a quick fix

Compose class is responsible for final response, so you can create a custom Compose class by implementing iCompose interface and then set Defaults::$composeClass to the class name of your custom class. Here is an example

class CustomCompose implements iCompose
{
    public static $includeDebugInfo = true;
    public $restler;

    public function response($result)
    {
        if ($this->restler->responseCode == 204) {
            return '';
        }
        return $result;
    }

    public function message(RestException $exception)
    {
        $r = array(
            'error' => array(
                    'code' => $exception->getCode(),
                    'message' => $exception->getErrorMessage(),
                ) + $exception->getDetails()
        );
        if (!Scope::get('Restler')->getProductionMode() && self::$includeDebugInfo) {
            $r += array(
                'debug' => array(
                    'source' => $exception->getSource(),
                    'stages' => $exception->getStages(),
                )
            );
        }
        return $r;
    }
}

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

No branches or pull requests

2 participants