httpbin
httpbin copied to clipboard
Draft: Add more encodings
New endpoints:
/encoding/<charset>
/encoding/<charset>/<base64body>
You could generate some url safe encodings like this:
for charset in utf-8 utf-16 utf-32 Shift_JIS EUC-JP; do
echo "https://httpbin.jskw.dev/encoding/${charset}/$(echo 'HTTPBIN は最高です🎉' | iconv -s -f 'utf-8' -t ${charset} 2> /dev/null | base64 | tr '/+' '_-')"
done
That script generates these URLs:
- https://httpbin.jskw.dev/encoding/utf-8/SFRUUEJJTiDjga_mnIDpq5jjgafjgZnwn46JCg==
- https://httpbin.jskw.dev/encoding/utf-16/_v8ASABUAFQAUABCAEkATgAgMG9nAJrYMGcwWdg834kACg==
- https://httpbin.jskw.dev/encoding/utf-32/AAD-_wAAAEgAAABUAAAAVAAAAFAAAABCAAAASQAAAE4AAAAgAAAwbwAAZwAAAJrYAAAwZwAAMFkAAfOJAAAACg==
- https://httpbin.jskw.dev/encoding/Shift_JIS/SFRUUEJJTiCCzY3FjYKCxYK3
- https://httpbin.jskw.dev/encoding/EUC-JP/SFRUUEJJTiCkz7rHueKkx6S5
And the browser (or any client) should be able to render the same chars, with the exception of the unicode specific '🎉'.
The existing endpoint https://httpbin.dev/encoding/utf8 continues to work the same with this change at https://httpbin.jskw.dev/encoding/utf8 -- and I also have it re-encode the demo into utf16 and utf32. It's interesting that Firefox does a better job at rendering utf16 but both Chrome and Firefox don't do utf32 at all.
To be fair the utility of utf16 and utf32 doesn't really make sense in the browser, it would only really make sense on specialized clients that need to be able to seek through unicode data without variable length encoding of the larger codepoints.
I've found that Firefox does pretty well with both utf-8 and utf-16 but not utf-32. Chrome makes a bit of a mess of the utf-8 demo re-encoded to utf-8.