provide option to set content for POST request with url_fetcher
This commit is contained in:
parent
940289639e
commit
fbb5091f94
2 changed files with 16 additions and 1 deletions
|
@ -90,12 +90,14 @@ void URLRequestFetchJob::StartAsync(scoped_ptr<base::Value> options) {
|
||||||
|
|
||||||
std::string url, method, referrer;
|
std::string url, method, referrer;
|
||||||
base::Value* session = nullptr;
|
base::Value* session = nullptr;
|
||||||
|
base::DictionaryValue* upload_data = nullptr;
|
||||||
base::DictionaryValue* dict =
|
base::DictionaryValue* dict =
|
||||||
static_cast<base::DictionaryValue*>(options.get());
|
static_cast<base::DictionaryValue*>(options.get());
|
||||||
dict->GetString("url", &url);
|
dict->GetString("url", &url);
|
||||||
dict->GetString("method", &method);
|
dict->GetString("method", &method);
|
||||||
dict->GetString("referrer", &referrer);
|
dict->GetString("referrer", &referrer);
|
||||||
dict->Get("session", &session);
|
dict->Get("session", &session);
|
||||||
|
dict->GetDictionary("uploadData", &upload_data);
|
||||||
|
|
||||||
// Check if URL is valid.
|
// Check if URL is valid.
|
||||||
GURL formated_url(url);
|
GURL formated_url(url);
|
||||||
|
@ -127,6 +129,14 @@ void URLRequestFetchJob::StartAsync(scoped_ptr<base::Value> options) {
|
||||||
else
|
else
|
||||||
fetcher_->SetReferrer(referrer);
|
fetcher_->SetReferrer(referrer);
|
||||||
|
|
||||||
|
// Set the data needed for POSTs.
|
||||||
|
if (upload_data && request_type == net::URLFetcher::POST) {
|
||||||
|
std::string content_type, data;
|
||||||
|
upload_data->GetString("contentType", &content_type);
|
||||||
|
upload_data->GetString("data", &data);
|
||||||
|
fetcher_->SetUploadData(content_type, data);
|
||||||
|
}
|
||||||
|
|
||||||
// Use |request|'s headers.
|
// Use |request|'s headers.
|
||||||
fetcher_->SetExtraRequestHeaders(
|
fetcher_->SetExtraRequestHeaders(
|
||||||
request()->extra_request_headers().ToString());
|
request()->extra_request_headers().ToString());
|
||||||
|
|
|
@ -103,11 +103,16 @@ Registers a protocol of `scheme` that will send a `String` as a response. The
|
||||||
|
|
||||||
Registers a protocol of `scheme` that will send an HTTP request as a response.
|
Registers a protocol of `scheme` that will send an HTTP request as a response.
|
||||||
The `callback` should be called with an object that has the `url`, `method`,
|
The `callback` should be called with an object that has the `url`, `method`,
|
||||||
`referrer`, and `session` properties.
|
`referrer`, `uploadData` and `session` properties.
|
||||||
|
|
||||||
By default the HTTP request will reuse the current session. If you want the
|
By default the HTTP request will reuse the current session. If you want the
|
||||||
request to have a different session you should set `session` to `null`.
|
request to have a different session you should set `session` to `null`.
|
||||||
|
|
||||||
|
POST request should provide an `uploadData` object.
|
||||||
|
* `uploadData` object
|
||||||
|
* `contentType` String - MIME type of the content.
|
||||||
|
* `data` String - Content to be sent.
|
||||||
|
|
||||||
### `protocol.unregisterProtocol(scheme[, completion])`
|
### `protocol.unregisterProtocol(scheme[, completion])`
|
||||||
|
|
||||||
* `scheme` String
|
* `scheme` String
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue