| |
| /pliant/util/encoding/http.pli |
| |
| 1 |
abstract | |
| 2 |
[HTTP protocol encoding/decoding] | |
| 3 |
| |
| 4 |
module "/pliant/language/unsafe.pli" | |
| 5 |
module "general.pli" | |
| 6 |
| |
| 7 |
| |
| 8 |
# the standard HTTP encoding | |
| 9 |
| |
| 10 |
gvar (Array uInt8 256) http_code := general_code "_.:@/$-+!*'()," | |
| 11 |
| |
| 12 |
function http_encode clear -> encoded | |
| 13 |
arg Str clear encoded | |
| 14 |
encoded := general_encode clear "%":number http_code | |
| 15 |
| |
| 16 |
function http_decode encoded -> ascii | |
| 17 |
arg Str encoded ascii | |
| 18 |
ascii := general_decode encoded "%":number | |
| 19 |
| |
| 20 |
export http_encode http_decode | |
| 21 |
| |
| 22 |
| |
| 23 |
# slash encoding is the minimal encoding to remove '/' in order to prepare futher parsing | |
| 24 |
| |
| 25 |
gvar (Array uInt8 256) slash_code | |
| 26 |
function setup | |
| 27 |
for (var Int u) 0 255 | |
| 28 |
slash_code u := shunt u<>"%":number and u<>"/":number u 0 | |
| 29 |
setup | |
| 30 |
| |
| 31 |
function http_slash_encode clear -> encoded | |
| 32 |
arg Str clear encoded | |
| 33 |
encoded := general_encode clear "%":number slash_code | |
| 34 |
| |
| 35 |
function http_slash_decode encoded -> ascii | |
| 36 |
arg Str encoded ascii | |
| 37 |
ascii := general_decode encoded "%":number | |
| 38 |
| |
| 39 |
export http_slash_encode http_slash_decode | |
| |