Inlined read_cookie function.