linkedin/atscppapi — pull request #9 by manjeshnilange (2013-07-10 21:27:15+00:00)
Title: Creating empty string values for headers with no values

For some headers with no values, ATS returns empty strings, but for some, it returns 0 as the count of values. For example, if you send a request such as

Accept-Encoding:
Accept-Language:
Content-Length:

For the first 2, ATS returns 1 as the number of values and an empty string as the actual value. But specifically for Content-Length, it returns 0 as the number of values. The main problem this causes is that user cannot assume that the value list of a header will always be non-empty. Instead of just doing

Headers::const_iterator header_iter = headers.find("Header1");
const string &value = iter->second.front(); // use 1st value

they'd have to do

const string EMPTY_STRING;
Headers::const_iterator header_iter = headers.find("Header1");
const string &value = header_iter->second.empty() ? EMPTY_STRING : iter->second.front(); // use 1st value

The second approach is ugly IMO and definitely inconvenient. In this patch, we add an empty string as the value when ATS returns 0 as the number of values. Note that ATS is already doing this - i.e., returning empty strings for most headers. I don't know why Content-Length is a special case or how many other special cases there are, but we can provide this consistency in this library.