// Crate a CharArrayBuffer with an arbitrary initial capacity.
CharArrayBuffer buffer = new CharArrayBuffer(100);
Iterator<Map.Entry<String, String[]>> responseHeadersIt =
mData.getHeaders().entrySet().iterator();
while (responseHeadersIt.hasNext()) {
Map.Entry<String, String[]> entry = responseHeadersIt.next();
// Headers.parseHeader() expects lowercase keys, so keys
// such as "Accept-Ranges" will fail to parse.
//
// UrlInterceptHandler instances supply a mapping of
// lowercase key to [ unmodified key, value ], so for
// Headers.parseHeader() to succeed, we need to construct
// a string using the key (i.e. entry.getKey()) and the
// element denoting the header value in the
// [ unmodified key, value ] pair (i.e. entry.getValue()[1).
//
// The reason why UrlInterceptHandler instances supply such a
// mapping in the first place is historical. Early versions of
// the Gears plugin used java.net.HttpURLConnection, which always
// returned headers names as capitalized strings. When these were
// fed back into webkit, they failed to parse.
//
// Mewanwhile, Gears was modified to use Apache HTTP library
// instead, so this design is now obsolete. Changing it however,
// would require changes to the Gears C++ codebase and QA-ing and
// submitting a new binary to the Android tree. Given the
// timelines for the next Android release, we will not do this
// for now.
//
// TODO: fix C++ Gears to remove the need for this
// design.
String keyValue = entry.getKey() + ": " + entry.getValue()[1];
buffer.ensureCapacity(keyValue.length());
buffer.append(keyValue);
// Parse it into the header container.
headers.parseHeader(buffer);
// Clear the buffer
buffer.clear();
}