Merge pull request #1738 from deepak1556/http_ptach

webContents: providing header details with response event
This commit is contained in:
Cheng Zhao 2015-05-27 15:05:55 +08:00
commit 1c60575dc0
4 changed files with 21 additions and 6 deletions

View file

@ -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,13 +312,27 @@ void WebContents::DidStopLoading() {
void WebContents::DidGetResourceResponseStart(
const content::ResourceRequestDetails& details) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
mate::Dictionary response_headers(isolate, v8::Object::New(isolate));
net::HttpResponseHeaders* headers = details.response_info.headers.get();
void* iter = nullptr;
std::string key;
std::string value;
while (headers && headers->EnumerateHeaderLines(&iter, &key, &value))
response_headers.Set(base::StringToLowerASCII(key),
base::StringToLowerASCII(value));
Emit("did-get-response-details",
details.socket_address.IsEmpty(),
details.url,
details.original_url,
details.http_response_code,
details.method,
details.referrer);
details.referrer,
response_headers);
}
void WebContents::DidGetRedirectForResourceRequest(

View file

@ -10,7 +10,8 @@ WEB_VIEW_EVENTS =
'did-start-loading': []
'did-stop-loading': []
'did-get-response-details': ['status', 'newUrl', 'originalUrl',
'httpResponseCode', 'requestMethod', 'referrer']
'httpResponseCode', 'requestMethod', 'referrer',
'headers']
'did-get-redirect-request': ['oldUrl', 'newUrl', 'isMainFrame']
'dom-ready': []
'console-message': ['level', 'message', 'line', 'sourceId']

View file

@ -694,11 +694,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'

View file

@ -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