Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requests with duplicate User-Agent HTTP headers fail to log to analytics #309

Closed
GUI opened this issue Jan 21, 2016 · 1 comment
Closed

Comments

@GUI
Copy link
Member

GUI commented Jan 21, 2016

I spotted a recent uptick of some errors in the web server logs due to specific requests failing to go into the analytics database. The issue was related to requests that had multiple User-Agent HTTP headers present, like:

curl -v -H "User-Agent: foo" -H "User-Agent: bar" "http://example.com/"
> GET / HTTP/1.1
> Host: example.com
> Accept: */*
> User-Agent: foo
> User-Agent: bar

User-Agent is not a HTTP header that technically supports multiple values (other headers do), but if two separate User-Agent headers were given, we were parsing that as an array of multiple values, which confused some subsequent processing that was expecting a string value.

@GUI
Copy link
Member Author

GUI commented Jan 21, 2016

This is fixed by: NREL/api-umbrella@0503e51

This also fixes other possible problems with logging that may have cropped up if multiple values were present on any other HTTP headers (although, I'm not aware of any of the other headers having caused problems). We now ensure that we're always logging a single string value for each HTTP header, rather than possibly having an array of multiple values. But the string value may differ slightly for some headers according to these rules:

  • For certain HTTP headers that explicitly don't support multiple values (User-Agent being one of them), we only take the first HTTP header value seen.
  • For all other HTTP headers, we comma-separate multiple values into a single string.

This logic seems to be the standard way to handle header parsing, which I took from Node.js's HTTP parser (which in turn took it from Firefox).

@GUI GUI closed this as completed Jan 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant