Fixing code review issues: function call formatting, renaming JS member variables, refactoring response headers conversion.

This commit is contained in:
ali.ibrahim 2016-10-13 17:14:23 +02:00
parent b290415bbd
commit 6f5b0a28c5
9 changed files with 272 additions and 185 deletions

View file

@ -10,6 +10,7 @@
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "native_mate/dictionary.h"
#include "net/base/upload_bytes_element_reader.h"
@ -58,6 +59,32 @@ v8::Local<v8::Value> Converter<scoped_refptr<net::X509Certificate>>::ToV8(
return dict.GetHandle();
}
// static
v8::Local<v8::Value>
Converter<scoped_refptr<const net::HttpResponseHeaders>>::ToV8(
v8::Isolate* isolate,
scoped_refptr<const net::HttpResponseHeaders> headers) {
base::DictionaryValue response_headers;
if (headers) {
size_t iter = 0;
std::string key;
std::string value;
while (headers->EnumerateHeaderLines(&iter, &key, &value)) {
key = base::ToLowerASCII(key);
if (response_headers.HasKey(key)) {
base::ListValue* values = nullptr;
if (response_headers.GetList(key, &values))
values->AppendString(value);
} else {
std::unique_ptr<base::ListValue> values(new base::ListValue());
values->AppendString(value);
response_headers.Set(key, std::move(values));
}
}
}
return ConvertToV8(isolate, response_headers);
}
} // namespace mate
namespace atom {

View file

@ -17,6 +17,7 @@ namespace net {
class AuthChallengeInfo;
class URLRequest;
class X509Certificate;
class HttpResponseHeaders;
}
namespace mate {
@ -33,6 +34,12 @@ struct Converter<scoped_refptr<net::X509Certificate>> {
const scoped_refptr<net::X509Certificate>& val);
};
template<>
struct Converter<scoped_refptr<const net::HttpResponseHeaders>> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
scoped_refptr<const net::HttpResponseHeaders> headers);
};
} // namespace mate
namespace atom {