avoid error accessing optional header User-Agent

The User-Agent header is an optional header by the client so we have to check if it exists.