2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-08-30 16:16:41 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 08:30:26 +08:00
|
|
|
#include "atom/browser/net/url_request_string_job.h"
|
2013-08-30 16:16:41 +08:00
|
|
|
|
2014-03-16 09:13:06 +08:00
|
|
|
#include <string>
|
|
|
|
|
2015-12-01 16:21:15 +08:00
|
|
|
#include "atom/common/atom_constants.h"
|
2013-08-30 16:16:41 +08:00
|
|
|
#include "net/base/net_errors.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
2015-08-12 22:57:25 +08:00
|
|
|
URLRequestStringJob::URLRequestStringJob(
|
|
|
|
net::URLRequest* request, net::NetworkDelegate* network_delegate)
|
|
|
|
: JsAsker<net::URLRequestSimpleJob>(request, network_delegate) {
|
2015-08-12 13:30:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void URLRequestStringJob::StartAsync(scoped_ptr<base::Value> options) {
|
2015-08-12 13:43:27 +08:00
|
|
|
if (options->IsType(base::Value::TYPE_DICTIONARY)) {
|
|
|
|
base::DictionaryValue* dict =
|
|
|
|
static_cast<base::DictionaryValue*>(options.get());
|
|
|
|
dict->GetString("mimeType", &mime_type_);
|
|
|
|
dict->GetString("charset", &charset_);
|
|
|
|
dict->GetString("data", &data_);
|
|
|
|
} else if (options->IsType(base::Value::TYPE_STRING)) {
|
|
|
|
options->GetAsString(&data_);
|
2015-08-12 13:30:19 +08:00
|
|
|
}
|
|
|
|
net::URLRequestSimpleJob::Start();
|
2013-08-30 16:16:41 +08:00
|
|
|
}
|
|
|
|
|
2015-09-15 19:54:16 +05:30
|
|
|
void URLRequestStringJob::GetResponseInfo(net::HttpResponseInfo* info) {
|
|
|
|
std::string status("HTTP/1.1 200 OK");
|
|
|
|
net::HttpResponseHeaders* headers = new net::HttpResponseHeaders(status);
|
|
|
|
|
2015-12-01 16:21:15 +08:00
|
|
|
headers->AddHeader(kCORSHeader);
|
2015-11-23 23:29:49 -08:00
|
|
|
|
2015-09-15 19:54:16 +05:30
|
|
|
if (!mime_type_.empty()) {
|
|
|
|
std::string content_type_header(net::HttpRequestHeaders::kContentType);
|
|
|
|
content_type_header.append(": ");
|
|
|
|
content_type_header.append(mime_type_);
|
|
|
|
headers->AddHeader(content_type_header);
|
|
|
|
}
|
|
|
|
|
|
|
|
info->headers = headers;
|
|
|
|
}
|
|
|
|
|
2013-08-30 16:16:41 +08:00
|
|
|
int URLRequestStringJob::GetData(
|
|
|
|
std::string* mime_type,
|
|
|
|
std::string* charset,
|
|
|
|
std::string* data,
|
|
|
|
const net::CompletionCallback& callback) const {
|
|
|
|
*mime_type = mime_type_;
|
|
|
|
*charset = charset_;
|
|
|
|
*data = data_;
|
|
|
|
return net::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace atom
|