Веб-служба REST: допустимый тип содержимого ответа HTTP при ответе со статусом 4XX (ошибка клиента)

Мне не удалось найти какую-либо документацию в спецификациях HTTP, которая определяет, допустимо ли генерировать HTTP-ответ, включая читаемое человеком сообщение об ошибке (например, content-type: text / plain), если HTTP-клиент сделал недопустимый HTTP-запрос, и указал заголовок запроса, который ограничивает допустимые типы содержимого ответа, используя заголовок принятия.

Представьте себе, что клиент веб-службы REST отправляет недопустимый запрос GET на «http: // myhost / validpath? НелегальныйRequestParameter = rubbish» и включает заголовок запроса «Accept: application / xml» или & quot; Принять: application / vnd.ms-excel & quot ;.

Сервер ответил бы кодом состояния HTTP в серии 4XX (в данном случае «400 Bad Request»). Но как служба сможет передать клиенту информацию о причине ошибки?

Я вижу следующие варианты:

Create a plaintext error message in the HTTP response content. Set response header "Content-type: text/plain" and include a descriptive error message in the response content. This would, however, break the HTTP client's "Accept" restriction.

Don't include a HTTP response content. This is clearly valid, but not very helpful to the client that just knows that a "Client Error" occurred but has no way of knowing why (and reporting the reason in a client log file).

Try to coerce an error message into an "Accept'able" MIME type. This is rarely possible. Even if the error message could be constructed as a valid application/xml type, it would likely break a web service contract (e.g. XML Schema conformance).

My question is: Is the above situation governed by existing HTTP specifications/standards?

Рекомендации:

HTTP Status Code Definitions: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html HTTP Header Field Definitions http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

Ответы на вопрос(1)

Ваш ответ на вопрос