1

It's useful to add custom HTTP header to provide application specific metadata or information to client, and hoping one day it can be a standard like link header (Web Linking).

Most of HTTP headers are designed under RFC 2616 specification with char, : | < | > | ; | = | " | ' |, etc. It's more close to human readable string than machine readable (easy to parse or not).

Now, I want to add a custom HTTP header to contain a structure information, which is easy to represent in object format like JSON object. Is it OK to add a custom HTTP header which it's value is a serialized JSON object or I should follow the convention to reformat it into some kind format like link header?

Hoping you guys can provide some advices on this, or other best practices to do it.

Thanks.

4
  • You can always Base 64 encode the header value. Make sure your header name starts with X-. Commented Jun 13, 2013 at 9:33
  • How does prefixing with "X-" affects things? Commented Jun 13, 2013 at 10:29
  • 1
    The X- prefix is obsolete for quite some time. There is no need for anymore. Commented Jun 13, 2013 at 10:37
  • 1
    1. the "X-" prefixing rule of private HTTP header is deprecated to gain backward compatibility when this header becomes a standard one. 2. I think Base 64 encoding is used only it's necessary to remain the readability, but thanks!. Commented Jun 13, 2013 at 11:51

1 Answer 1

1

If you need JSON, use JSON. Be sure to get non-ASCII characters right, though.

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

11 Comments

Correct, you can rely here on URI encoding. This is a safe bet.
Michael-O: URI encoding is total overkill for that. Just make sure to generate a pure ASCII JSON serialization.
No, it's. Only non-ASCII chars will be encoded. Otherwise you won't have Unicode at all.
Michael-O: URI encoding changes also ASCII-characters, such as "&", "<" and ">". There's no point in doing so in a header field value.
At least, it makes the entire value ASCII-safe.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.