Draft: Add more encodings by BlackthornYugen · Pull Request #45 · psf/httpbin · GitHub
Skip to content

Draft: Add more encodings#45

Draft
BlackthornYugen wants to merge 1 commit into
psf:mainfrom
BlackthornYugen:main
Draft

Draft: Add more encodings#45
BlackthornYugen wants to merge 1 commit into
psf:mainfrom
BlackthornYugen:main

Conversation

@BlackthornYugen

@BlackthornYugen BlackthornYugen commented Jun 16, 2024

Copy link
Copy Markdown

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:

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.

@BlackthornYugen

BlackthornYugen commented Jun 17, 2024

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant