Here is a properly spec'ed and tested folded API header. I realize this implementation incurs a performance penalty by generating JSON twice for long headers, but this way tests don't break and short API headers remain as terse as possible.
The optimal solution would be to use a SAX style JSON parser on the original JSON string to insert spaces strategically, but I don't think that merits the inclusion of another dependency.
Here is a properly spec'ed and tested folded API header. I realize this implementation incurs a performance penalty by generating JSON twice for long headers, but this way tests don't break and short API headers remain as terse as possible.
The optimal solution would be to use a SAX style JSON parser on the original JSON string to insert spaces strategically, but I don't think that merits the inclusion of another dependency.