プロジェクト

全般

プロフィール

Vote #72211

完了

Updating a version through rest API returns invalid JSON

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
REST API_32
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
32
version_id:
47
issue_org_id:
11388
author_id:
49990
assigned_to_id:
1
comments:
15
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
52
ステータス-->[Closed]

説明

After PUTing a successful version update API request to @/versions/1234.json@, a response body consisting of one space is returned, while it declares itself to be 'Content-Type: application/json'.

One space (" ") is not valid JSON, so a client interpreting the response according to the content-type header will issue an error.

(reported before in #9598, but does not mention content-type clash)


journals

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Lets define the expected behaviour first.
--------------------------------------------------------------------------------
A more appropriate response should be a 204 response but I guess it could break some API clients. So I propose to respond with a 200 and an empty body. Should we keep the Content-Type as it is now?
--------------------------------------------------------------------------------
There has been "a related commit":https://github.com/rails/rails/commit/0d3333257156544feba729ba28f6874d5a30d561 in RoR ("original LH ticket":https://rails.lighthouseapp.com/projects/8994/tickets/5199-respond_with-returns-on-put-and-delete-verb) to return an empty object (because setting Content-Type and no body makes no sense either I guess).

After discussion, it was eventually overrided by "a new commit":https://github.com/rails/rails/commit/80768b739ed7e2053d85a01dd5fa60bde67aad9a setting the response code to @204@ and setting the body back to an single space.

I would do the way Rails do.

Edit: not an empty string, a single space.

--------------------------------------------------------------------------------
The default Rails behaviour is now a @204 No Content@ with a non-empty body, really?
--------------------------------------------------------------------------------
Jean-Philippe Lang wrote:
> The default Rails behaviour is now a @204 No Content@ with a non-empty body, really?

Well, I did not test but that's what the code and commit say :D

<pre>...
<code class="ruby">
assert_equal 204, @response.status
assert_equal " ", @response.body
</code>...</pre>

--------------------------------------------------------------------------------
I have made a few tests with JQuery. It gives an error when responding with a one space response body indeed. But it seems to work fine with a 200 response and an empty body, even if the response Content-Type is set to text/json. It gives no error and returns null.

So I propose to just change the "one space" response body to an empty body.
--------------------------------------------------------------------------------
Did you try with a @204@ and a single space?
--------------------------------------------------------------------------------
No, but I really don't want to change the API behaviour in this way and break compatibility.
--------------------------------------------------------------------------------
Etienne Massip wrote:
> Did you try with a @204@ and a single space?

It seems to behave just like with an empty 200 response.
--------------------------------------------------------------------------------
FTR, there exists a "jQuery bug":http://bugs.jquery.com/ticket/7099 which has been closed.

Quote : ??An example of this is the 204 No Content status. The HTTP specification is unclear as to the inclusion of content-type. It does not forbid including it at any rate. *But it does forbid the inclusion of a message-body.*??

--------------------------------------------------------------------------------
Jean-Philippe Lang wrote:
> So I propose to just change the "one space" response body to an empty body.

Agreed.

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
No feedback about the change, it will wait for 2.1.0.
--------------------------------------------------------------------------------


related_issues

relates,Closed,9598,JSON REST API : PUT returns one space character
duplicates,Closed,11491,JSON / XML format : delete / put dont send any data

Admin Redmine さんが3年以上前に更新

  • カテゴリREST API_32 にセット
  • 対象バージョン2.1.0_47 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0