tags:

views:

523

answers:

4

In the HTTP header, line breaks are tokens to separate fields in the header.

But, if I wan't to send a line break literal in a custom field how should I escape it?

A: 

I hope I'm understanding your question, but typical line break sequence are "\n" "\t" "\r".

Dave
+3  A: 

If you are designing your own custom extension field, you may use BASE64 or quoted-printable to escape(and unescape) the value.

Dennis Cheung
+1 - means you don't have to worry about out of bounds characters, what character encoding is in use, etc. The RFC822-native ways of encapsulating these things are horrible, fragile, and typically won't work in HTTP.
bobince
A: 

If it's a custom field how you escape it depends entirely on how the targetted application is going to parse it. If this is some add on you created you could stick with URL encoding since it's pretty tried and true and lots of languages have encoding/decoding methods built in so your web app would encode it and your plug in (or whatever you're working on) would decode it.

Spencer Ruport
+2  A: 

According to RFC2616 4.2 Message Headers :-

Header fields can be extended over multiple lines by preceding each extra line with at least one SP or HT.

I assume SP means a space character and HT means a hard tab character.

floehopper
Don't expect the newline to come out in the parsed version your app may get though; this mechanism exists historically from RFC822 only to fold long header lines into 80 characters.
bobince

related questions