Improve str_to_int() et al

Always set *afterp to point to the first invalid character
even if conversion fails
fixup! fixup! fixup! fixup! Refactor HTTP server code