Fix a KeyError when there's no User-Agent header field 

I happened to find 500 errors for requests without the User-Agent header field. I apologize that I have not tested this code. I'd appreciate it if anyone could run a test before merging. Thanks.