0

I have web application written in Yii2. Inside beforeAction() i want to set my custom message to user with explanation of problem:

Yii::$app->response->setStatusCode(403, 'Brak dostępu. Skontaktuj się z administratorem.'); 

Is it possible to use uft-8 "reason text" in HTTP/1.1 response header?

2
  • 1
    I don’t see what a translation should achieve in that place to begin with. If you want to show a translated error message to the user in the page, that would be one thing - but HTTP headers should rather not need “translating” in the first place IMHO. Commented Feb 25, 2019 at 14:08
  • You can also include an HTML body. Under most conditions, a web browser would display it. Commented Feb 25, 2019 at 18:09

1 Answer 1

2

RFC 7230 does not give any instructions on how to parse the "reason text" element of the status line, so no encoding is implied or specified.

The ABNF grammar indicates that your string would be valid if presented in any "ASCII-compatible" encoding, such as UTF-8:

reason-phrase = *( HTAB / SP / VCHAR / obs-text ) 

VCHAR means "visible ASCII character", and obs-text is any byte in the range 0x80 to 0xFF.

However, there is no definition of how those bytes should be interpreted. Instead, the specification recommends that clients do not parse it at all:

The reason-phrase element exists for the sole purpose of providing a textual description associated with the numeric status code, mostly out of deference to earlier Internet application protocols that were more frequently used with interactive text clients. A client SHOULD ignore the reason-phrase content.

So go ahead and put whatever text you like there if you're using it for low-level debugging or with a custom client. But don't be surprised if standard clients either ignore it or misinterpret it as a different character encoding.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.