From 4d5790dc09dcad616d34aa476b1551e978e72939 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Fri, 22 May 2015 02:52:52 +0530 Subject: [PATCH] return headers as object --- atom/browser/api/atom_api_web_contents.cc | 13 ++++++++++++- .../native_mate_converters/value_converter.cc | 7 +++++++ .../common/native_mate_converters/value_converter.h | 2 ++ docs/api/browser-window.md | 3 +-- docs/api/web-view-tag.md | 3 +-- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index a361d747..23bdc24c 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -18,6 +18,7 @@ #include "atom/common/native_mate_converters/image_converter.h" #include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/native_mate_converters/value_converter.h" +#include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "brightray/browser/inspectable_web_contents.h" #include "brightray/browser/media/media_stream_devices_controller.h" @@ -38,6 +39,7 @@ #include "native_mate/callback.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" +#include "net/http/http_response_headers.h" #include "net/url_request/url_request_context.h" #include "atom/common/node_includes.h" @@ -310,6 +312,15 @@ void WebContents::DidStopLoading() { void WebContents::DidGetResourceResponseStart( const content::ResourceRequestDetails& details) { + net::HttpResponseHeaders* headers = details.headers.get(); + base::DictionaryValue response_headers; + void* iter = nullptr; + std::string key; + std::string value; + while (headers && headers->EnumerateHeaderLines(&iter, &key, &value)) { + response_headers.SetString(base::StringToLowerASCII(key), + base::StringToLowerASCII(value)); + } Emit("did-get-response-details", details.socket_address.IsEmpty(), details.url, @@ -317,7 +328,7 @@ void WebContents::DidGetResourceResponseStart( details.http_response_code, details.method, details.referrer, - details.header); + response_headers); } void WebContents::DidGetRedirectForResourceRequest( diff --git a/atom/common/native_mate_converters/value_converter.cc b/atom/common/native_mate_converters/value_converter.cc index 815ba0eb..79716230 100644 --- a/atom/common/native_mate_converters/value_converter.cc +++ b/atom/common/native_mate_converters/value_converter.cc @@ -23,6 +23,13 @@ bool Converter::FromV8(v8::Isolate* isolate, } } +v8::Handle Converter::ToV8( + v8::Isolate* isolate, + const base::DictionaryValue& val) { + scoped_ptr converter(new atom::V8ValueConverter); + return converter->ToV8Value(&val, isolate->GetCurrentContext()); +} + bool Converter::FromV8(v8::Isolate* isolate, v8::Local val, base::ListValue* out) { diff --git a/atom/common/native_mate_converters/value_converter.h b/atom/common/native_mate_converters/value_converter.h index bb0ef66e..27e00f45 100644 --- a/atom/common/native_mate_converters/value_converter.h +++ b/atom/common/native_mate_converters/value_converter.h @@ -19,6 +19,8 @@ struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Local val, base::DictionaryValue* out); + static v8::Handle ToV8(v8::Isolate* isolate, + const base::DictionaryValue& val); }; template<> diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index cc68f200..f7bc6396 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -674,11 +674,10 @@ Corresponds to the points in time when the spinner of the tab stops spinning. * `httpResponseCode` Integer * `requestMethod` String * `referrer` String -* `headers` String +* `headers` Object Emitted when details regarding a requested resource is available. `status` indicates the socket connection to download the resource. -`headers` is key-value string separated by new-line character. ### Event: 'did-get-redirect-request' diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index a1a472a5..96484649 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -333,11 +333,10 @@ Corresponds to the points in time when the spinner of the tab stops spinning. * `httpResponseCode` Integer * `requestMethod` String * `referrer` String -* `headers` String +* `headers` Object Fired when details regarding a requested resource is available. `status` indicates socket connection to download the resource. -`headers` is key-value string separated by new-line character. ### did-get-redirect-request -- 2.43.0