Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Response status of a REST controller if format not supported or not set
  • If the format is not supported or not set, fuel doesn't set the status of the response but return the data. Is that really logical ?

    For example, if I want to set a special status because some parameters are missing in the request I can't do that if the format is not asked explicitly.
  • There is always a valid format, if all else fails it will fall back to the format defined in the rest config file, which is 'xml' by default.

    So your case isn't really valid, if you want a specific format you'll have to check $this->format in your method.

  • Thanks for the response.

    Ok but by default it's return html. I think there is a problem in the _detect_format method. It pass in the " if (\Input::server('HTTP_ACCEPT') and \Config::get('rest.ignore_http_accept') !== true) " on line 229 on so it return html and not the default format, I don't really understand what's append.

    And this don't explain why it doesn't set the status if the format is not supported in the else scope line 196. I think the line 190 need to be after the if else structure, no ?
  • It will return HTML if you request the method by the browser, as that's what the HTTP_ACCEPT header says you accept. In normal circumstances it will never reach the "if all else fails" bit...

    So when and why do you think you get an unsupported format?
  • OK thanks for the explanation.

    I don't say that I get an unsupported format, I simply make a reference to the comment on line 193 "// Format not supported, output directly".

    My problem is when I call for example http://monsite.com/controller/method without the format specify. If I pass a status in the response method this status will not be set by the response method.

    Example :
    If I want to return :

    $this->response('Response text', 400);
    The status 400 is not return.
  • Note that your method should return the return value of $this->response(), if not the after() method will construct a new response due to a lack of response from your method.

    Post your method on http://snipr.it so I can have a look.

    Your method can also simply do
    $this->response->status = 400;
    return 'Response text';
  • Here is my method : http://snipr.it/~uv/3658d8074fa78cd5896e4c1dc7c30d40

    I have we can directly set the status property but I we have a parameters for that in response method so I wanted to use it.
  • HarroHarro
    Accepted Answer
    Ok, did some debugging and it does indeed ignore the status in response() if the format defined is not supported by the Format class.

    Fixed here: https://github.com/fuel/core/commit/f391be45a8155e5e4dedfe0d93cf0ffaec7ed10d

    You can backport this to 1.4 without problems.
  • That's what I thought thank you for the fix.
  • Did you make any support of 1.4 branch cause we use your github repository to our development and it's a bug so ?
  • I haven't backported it, and I expect a 1.5 to be released soon, I don't think I will.

    If you're using git, and you sync with our repo, cherry picking is easy enough.
  • Ok thank you for the precision.
    Glad to hear that the 1.5 will be released soon :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion