let escape s =
let b = Buffer.create (String.length s) in
String.iter s (function
| 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' as c -> Buffer.add_char b c
| anyother -> Buffer.add_string b (sprintf "%%%02X" (Char.to_int anyother)));
Buffer.contents b