1
This commit is contained in:
parent
ae2a2bcddb
commit
5954fb5fcb
@ -9,24 +9,38 @@
|
|||||||
namespace f8
|
namespace f8
|
||||||
{
|
{
|
||||||
|
|
||||||
JsonHttpRequest::JsonHttpRequest()
|
JsonHttpRequest::JsonHttpRequest(unsigned long saddr,
|
||||||
|
const std::string url,
|
||||||
|
const std::string& query_str,
|
||||||
|
a8::CommonCbProc cb)
|
||||||
{
|
{
|
||||||
params = std::make_shared<a8::XObject>();
|
saddr_ = saddr;
|
||||||
resp_xobj = a8::MutableXObject::CreateObject();
|
url_ = url;
|
||||||
|
query_str_ = query_str;
|
||||||
|
cb_ = cb;
|
||||||
|
params_ = std::make_shared<a8::XObject>();
|
||||||
|
resp_xobj_ = a8::MutableXObject::CreateObject();
|
||||||
|
|
||||||
|
params_->ReadFromUrlQueryString(query_str);
|
||||||
|
GetResp()->SetVal("errcode", 0);
|
||||||
|
GetResp()->SetVal("errmsg", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonHttpRequest::~JsonHttpRequest()
|
JsonHttpRequest::~JsonHttpRequest()
|
||||||
{
|
{
|
||||||
if (context && free_context) {
|
Response();
|
||||||
free_context(context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string JsonHttpRequest::Response()
|
void JsonHttpRequest::Response()
|
||||||
{
|
{
|
||||||
|
if (!resped_) {
|
||||||
|
if (cb_) {
|
||||||
std::string response;
|
std::string response;
|
||||||
resp_xobj->ToJsonStr(response);
|
resp_xobj_->ToJsonStr(response);
|
||||||
return a8::HttpResponse(response);
|
cb_(a8::Args({a8::HttpResponse(response)}));
|
||||||
|
}
|
||||||
|
resped_ = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,24 +9,28 @@ namespace a8
|
|||||||
namespace f8
|
namespace f8
|
||||||
{
|
{
|
||||||
|
|
||||||
struct JsonHttpRequest
|
class JsonHttpRequest
|
||||||
{
|
{
|
||||||
bool pending = false;
|
private:
|
||||||
unsigned long saddr = 0;
|
unsigned long saddr_ = 0;
|
||||||
int socket_handle = 0;
|
std::string url_;
|
||||||
time_t create_time = 0;
|
std::string query_str_;
|
||||||
time_t handle_time = 0;
|
std::shared_ptr<a8::XObject> params_;
|
||||||
std::string query_str;
|
std::shared_ptr<a8::MutableXObject> resp_xobj_;
|
||||||
std::shared_ptr<a8::XObject> params;
|
a8::CommonCbProc cb_;
|
||||||
std::shared_ptr<a8::MutableXObject> resp_xobj;
|
bool resped_ = false;
|
||||||
|
|
||||||
int async_pending_count = 0;
|
public:
|
||||||
void* context = nullptr;
|
JsonHttpRequest(unsigned long saddr,
|
||||||
void (*free_context)(void*) = nullptr;
|
const std::string url,
|
||||||
|
const std::string& query_str,
|
||||||
JsonHttpRequest();
|
a8::CommonCbProc cb);
|
||||||
~JsonHttpRequest();
|
~JsonHttpRequest();
|
||||||
std::string Response();
|
|
||||||
|
const std::string GetUrl() { return this->url_; }
|
||||||
|
std::shared_ptr<a8::XObject> GetParams() { return this->params_; }
|
||||||
|
std::shared_ptr<a8::MutableXObject> GetResp() { return this->resp_xobj_; }
|
||||||
|
void Response();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user