Better content-type negotiation

- Don't pull the header value on each iteration of the loop
- Get the media type of the header value before comparisons
- Ensure there is no whitespace around the media type