protocol: provide upload data when available
This commit is contained in:
parent
d2e63dfc64
commit
940289639e
1 changed files with 29 additions and 0 deletions
|
@ -5,9 +5,14 @@
|
|||
#include "atom/common/native_mate_converters/net_converter.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "net/base/upload_bytes_element_reader.h"
|
||||
#include "net/base/upload_data_stream.h"
|
||||
#include "net/base/upload_element_reader.h"
|
||||
#include "net/base/upload_file_element_reader.h"
|
||||
#include "net/cert/x509_certificate.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
|
||||
|
@ -20,6 +25,30 @@ v8::Local<v8::Value> Converter<const net::URLRequest*>::ToV8(
|
|||
dict.Set("method", val->method());
|
||||
dict.Set("url", val->url().spec());
|
||||
dict.Set("referrer", val->referrer());
|
||||
const net::UploadDataStream* upload_data = val->get_upload();
|
||||
if (upload_data) {
|
||||
const ScopedVector<net::UploadElementReader>* readers =
|
||||
upload_data->GetElementReaders();
|
||||
std::vector<mate::Dictionary> upload_data_list;
|
||||
upload_data_list.reserve(readers->size());
|
||||
for (const auto& reader : *readers) {
|
||||
auto upload_data_dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
if (reader->AsBytesReader()) {
|
||||
const net::UploadBytesElementReader* bytes_reader =
|
||||
reader->AsBytesReader();
|
||||
auto bytes =
|
||||
node::Buffer::Copy(isolate, bytes_reader->bytes(),
|
||||
bytes_reader->length()).ToLocalChecked();
|
||||
upload_data_dict.Set("bytes", bytes);
|
||||
} else if (reader->AsFileReader()) {
|
||||
const net::UploadFileElementReader* file_reader =
|
||||
reader->AsFileReader();
|
||||
upload_data_dict.Set("file", file_reader->path().AsUTF8Unsafe());
|
||||
}
|
||||
upload_data_list.push_back(upload_data_dict);
|
||||
}
|
||||
dict.Set("uploadData", upload_data_list);
|
||||
}
|
||||
return mate::ConvertToV8(isolate, dict);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue