Permalink
Browse files

http, feat: support find method.

  • Loading branch information...
xicilion committed Sep 28, 2017
1 parent 1429a5f commit b7f14b1288d6c64304bbee5e8cf31078680d274c
@@ -56,6 +56,9 @@ class HttpClient : public HttpClient_base {
virtual result_t patch(exlib::string url, SeekableStream_base* body, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac);
virtual result_t patch(exlib::string url, Buffer_base* body, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac);
virtual result_t patch(exlib::string url, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac);
virtual result_t find(exlib::string url, SeekableStream_base* body, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac);
virtual result_t find(exlib::string url, Buffer_base* body, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac);
virtual result_t find(exlib::string url, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac);
public:
result_t update_cookies(exlib::string url, obj_ptr<List_base> cookies);
View
@@ -68,6 +68,8 @@ class Routing : public Routing_base {
virtual result_t put(exlib::string pattern, Handler_base* hdlr, obj_ptr<Routing_base>& retVal);
virtual result_t patch(v8::Local<v8::Object> map, obj_ptr<Routing_base>& retVal);
virtual result_t patch(exlib::string pattern, Handler_base* hdlr, obj_ptr<Routing_base>& retVal);
virtual result_t find(v8::Local<v8::Object> map, obj_ptr<Routing_base>& retVal);
virtual result_t find(exlib::string pattern, Handler_base* hdlr, obj_ptr<Routing_base>& retVal);
public:
result_t _append(exlib::string method, v8::Local<v8::Object> map, obj_ptr<Routing_base>& retVal);
@@ -57,6 +57,9 @@ class HttpClient_base : public object_base {
virtual result_t patch(exlib::string url, SeekableStream_base* body, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac) = 0;
virtual result_t patch(exlib::string url, Buffer_base* body, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac) = 0;
virtual result_t patch(exlib::string url, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac) = 0;
virtual result_t find(exlib::string url, SeekableStream_base* body, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac) = 0;
virtual result_t find(exlib::string url, Buffer_base* body, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac) = 0;
virtual result_t find(exlib::string url, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac) = 0;
public:
template <typename T>
@@ -81,6 +84,7 @@ class HttpClient_base : public object_base {
static void s_del(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_put(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_patch(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_find(const v8::FunctionCallbackInfo<v8::Value>& args);
public:
ASYNC_MEMBERVALUE3(HttpClient_base, request, Stream_base*, HttpRequest_base*, obj_ptr<HttpResponse_base>);
@@ -99,6 +103,9 @@ class HttpClient_base : public object_base {
ASYNC_MEMBERVALUE4(HttpClient_base, patch, exlib::string, SeekableStream_base*, v8::Local<v8::Object>, obj_ptr<HttpResponse_base>);
ASYNC_MEMBERVALUE4(HttpClient_base, patch, exlib::string, Buffer_base*, v8::Local<v8::Object>, obj_ptr<HttpResponse_base>);
ASYNC_MEMBERVALUE3(HttpClient_base, patch, exlib::string, v8::Local<v8::Object>, obj_ptr<HttpResponse_base>);
ASYNC_MEMBERVALUE4(HttpClient_base, find, exlib::string, SeekableStream_base*, v8::Local<v8::Object>, obj_ptr<HttpResponse_base>);
ASYNC_MEMBERVALUE4(HttpClient_base, find, exlib::string, Buffer_base*, v8::Local<v8::Object>, obj_ptr<HttpResponse_base>);
ASYNC_MEMBERVALUE3(HttpClient_base, find, exlib::string, v8::Local<v8::Object>, obj_ptr<HttpResponse_base>);
};
}
@@ -125,7 +132,9 @@ inline ClassInfo& HttpClient_base::class_info()
{ "put", s_put, false },
{ "putSync", s_put, false },
{ "patch", s_patch, false },
{ "patchSync", s_patch, false }
{ "patchSync", s_patch, false },
{ "find", s_find, false },
{ "findSync", s_find, false }
};
static ClassData::ClassProperty s_property[] = {
@@ -542,6 +551,51 @@ inline void HttpClient_base::s_patch(const v8::FunctionCallbackInfo<v8::Value>&
METHOD_RETURN();
}
inline void HttpClient_base::s_find(const v8::FunctionCallbackInfo<v8::Value>& args)
{
obj_ptr<HttpResponse_base> vr;
METHOD_INSTANCE(HttpClient_base);
METHOD_ENTER();
ASYNC_METHOD_OVER(3, 2);
ARG(exlib::string, 0);
ARG(obj_ptr<SeekableStream_base>, 1);
OPT_ARG(v8::Local<v8::Object>, 2, v8::Object::New(isolate));
if (!cb.IsEmpty()) {
pInst->acb_find(v0, v1, v2, cb);
hr = CALL_RETURN_NULL;
} else
hr = pInst->ac_find(v0, v1, v2, vr);
ASYNC_METHOD_OVER(3, 2);
ARG(exlib::string, 0);
ARG(obj_ptr<Buffer_base>, 1);
OPT_ARG(v8::Local<v8::Object>, 2, v8::Object::New(isolate));
if (!cb.IsEmpty()) {
pInst->acb_find(v0, v1, v2, cb);
hr = CALL_RETURN_NULL;
} else
hr = pInst->ac_find(v0, v1, v2, vr);
ASYNC_METHOD_OVER(2, 1);
ARG(exlib::string, 0);
OPT_ARG(v8::Local<v8::Object>, 1, v8::Object::New(isolate));
if (!cb.IsEmpty()) {
pInst->acb_find(v0, v1, cb);
hr = CALL_RETURN_NULL;
} else
hr = pInst->ac_find(v0, v1, vr);
METHOD_RETURN();
}
}
#endif
@@ -42,6 +42,8 @@ class Routing_base : public Handler_base {
virtual result_t put(exlib::string pattern, Handler_base* hdlr, obj_ptr<Routing_base>& retVal) = 0;
virtual result_t patch(v8::Local<v8::Object> map, obj_ptr<Routing_base>& retVal) = 0;
virtual result_t patch(exlib::string pattern, Handler_base* hdlr, obj_ptr<Routing_base>& retVal) = 0;
virtual result_t find(v8::Local<v8::Object> map, obj_ptr<Routing_base>& retVal) = 0;
virtual result_t find(exlib::string pattern, Handler_base* hdlr, obj_ptr<Routing_base>& retVal) = 0;
public:
template <typename T>
@@ -56,6 +58,7 @@ class Routing_base : public Handler_base {
static void s_del(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_put(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_patch(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_find(const v8::FunctionCallbackInfo<v8::Value>& args);
};
}
@@ -69,7 +72,8 @@ inline ClassInfo& Routing_base::class_info()
{ "post", s_post, false },
{ "del", s_del, false },
{ "put", s_put, false },
{ "patch", s_patch, false }
{ "patch", s_patch, false },
{ "find", s_find, false }
};
static ClassData s_cd = {
@@ -285,6 +289,29 @@ inline void Routing_base::s_patch(const v8::FunctionCallbackInfo<v8::Value>& arg
METHOD_RETURN();
}
inline void Routing_base::s_find(const v8::FunctionCallbackInfo<v8::Value>& args)
{
obj_ptr<Routing_base> vr;
METHOD_INSTANCE(Routing_base);
METHOD_ENTER();
METHOD_OVER(1, 1);
ARG(v8::Local<v8::Object>, 0);
hr = pInst->find(v0, vr);
METHOD_OVER(2, 2);
ARG(exlib::string, 0);
ARG(obj_ptr<Handler_base>, 1);
hr = pInst->find(v0, v1, vr);
METHOD_RETURN();
}
}
#endif
View
@@ -63,6 +63,9 @@ class http_base : public object_base {
static result_t patch(exlib::string url, SeekableStream_base* body, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac);
static result_t patch(exlib::string url, Buffer_base* body, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac);
static result_t patch(exlib::string url, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac);
static result_t find(exlib::string url, SeekableStream_base* body, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac);
static result_t find(exlib::string url, Buffer_base* body, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac);
static result_t find(exlib::string url, v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac);
public:
static void s__new(const v8::FunctionCallbackInfo<v8::Value>& args)
@@ -94,6 +97,7 @@ class http_base : public object_base {
static void s_del(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_put(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_patch(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_find(const v8::FunctionCallbackInfo<v8::Value>& args);
public:
ASYNC_STATICVALUE3(http_base, request, Stream_base*, HttpRequest_base*, obj_ptr<HttpResponse_base>);
@@ -112,6 +116,9 @@ class http_base : public object_base {
ASYNC_STATICVALUE4(http_base, patch, exlib::string, SeekableStream_base*, v8::Local<v8::Object>, obj_ptr<HttpResponse_base>);
ASYNC_STATICVALUE4(http_base, patch, exlib::string, Buffer_base*, v8::Local<v8::Object>, obj_ptr<HttpResponse_base>);
ASYNC_STATICVALUE3(http_base, patch, exlib::string, v8::Local<v8::Object>, obj_ptr<HttpResponse_base>);
ASYNC_STATICVALUE4(http_base, find, exlib::string, SeekableStream_base*, v8::Local<v8::Object>, obj_ptr<HttpResponse_base>);
ASYNC_STATICVALUE4(http_base, find, exlib::string, Buffer_base*, v8::Local<v8::Object>, obj_ptr<HttpResponse_base>);
ASYNC_STATICVALUE3(http_base, find, exlib::string, v8::Local<v8::Object>, obj_ptr<HttpResponse_base>);
};
}
@@ -145,7 +152,9 @@ inline ClassInfo& http_base::class_info()
{ "put", s_put, true },
{ "putSync", s_put, true },
{ "patch", s_patch, true },
{ "patchSync", s_patch, true }
{ "patchSync", s_patch, true },
{ "find", s_find, true },
{ "findSync", s_find, true }
};
static ClassData::ClassObject s_object[] = {
@@ -554,6 +563,50 @@ inline void http_base::s_patch(const v8::FunctionCallbackInfo<v8::Value>& args)
METHOD_RETURN();
}
inline void http_base::s_find(const v8::FunctionCallbackInfo<v8::Value>& args)
{
obj_ptr<HttpResponse_base> vr;
METHOD_ENTER();
ASYNC_METHOD_OVER(3, 2);
ARG(exlib::string, 0);
ARG(obj_ptr<SeekableStream_base>, 1);
OPT_ARG(v8::Local<v8::Object>, 2, v8::Object::New(isolate));
if (!cb.IsEmpty()) {
acb_find(v0, v1, v2, cb);
hr = CALL_RETURN_NULL;
} else
hr = ac_find(v0, v1, v2, vr);
ASYNC_METHOD_OVER(3, 2);
ARG(exlib::string, 0);
ARG(obj_ptr<Buffer_base>, 1);
OPT_ARG(v8::Local<v8::Object>, 2, v8::Object::New(isolate));
if (!cb.IsEmpty()) {
acb_find(v0, v1, v2, cb);
hr = CALL_RETURN_NULL;
} else
hr = ac_find(v0, v1, v2, vr);
ASYNC_METHOD_OVER(2, 1);
ARG(exlib::string, 0);
OPT_ARG(v8::Local<v8::Object>, 1, v8::Object::New(isolate));
if (!cb.IsEmpty()) {
acb_find(v0, v1, cb);
hr = CALL_RETURN_NULL;
} else
hr = ac_find(v0, v1, vr);
METHOD_RETURN();
}
}
#endif
@@ -603,4 +603,22 @@ result_t HttpClient::patch(exlib::string url, v8::Local<v8::Object> headers,
{
return request("PATCH", url, headers, retVal, ac);
}
result_t HttpClient::find(exlib::string url, Buffer_base* body,
v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac)
{
return request("FIND", url, body, headers, retVal, ac);
}
result_t HttpClient::find(exlib::string url, SeekableStream_base* body,
v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac)
{
return request("FIND", url, body, headers, retVal, ac);
}
result_t HttpClient::find(exlib::string url, v8::Local<v8::Object> headers,
obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac)
{
return request("FIND", url, headers, retVal, ac);
}
}
View
@@ -186,4 +186,22 @@ result_t http_base::patch(exlib::string url, v8::Local<v8::Object> headers,
{
return get_httpClient(ac->isolate())->patch(url, headers, retVal, ac);
}
result_t http_base::find(exlib::string url, Buffer_base* body,
v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac)
{
return get_httpClient(ac->isolate())->patch(url, body, headers, retVal, ac);
}
result_t http_base::find(exlib::string url, SeekableStream_base* body,
v8::Local<v8::Object> headers, obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac)
{
return get_httpClient(ac->isolate())->find(url, body, headers, retVal, ac);
}
result_t http_base::find(exlib::string url, v8::Local<v8::Object> headers,
obj_ptr<HttpResponse_base>& retVal, AsyncEvent* ac)
{
return get_httpClient(ac->isolate())->find(url, headers, retVal, ac);
}
}
View
@@ -379,4 +379,15 @@ result_t Routing::patch(exlib::string pattern, Handler_base* hdlr,
return append("PATCH", pattern, hdlr, retVal);
}
result_t Routing::find(v8::Local<v8::Object> map, obj_ptr<Routing_base>& retVal)
{
return _append("FIND", map, retVal);
}
result_t Routing::find(exlib::string pattern, Handler_base* hdlr,
obj_ptr<Routing_base>& retVal)
{
return append("FIND", pattern, hdlr, retVal);
}
} /* namespace fibjs */
View
@@ -157,4 +157,27 @@ interface HttpClient : object
@return 返回服务器响应
*/
HttpResponse patch(String url, Object headers = {}) async;
/*! @brief 用 FIND 方法请求指定的 url,并返回结果,等同于 request("PATCH", ...)
@param url 指定 url,必须是包含主机的完整 url
@param body 指定发送的 body 内容
@param headers 指定附加的 http 头,缺省无附加头
@return 返回服务器响应
*/
HttpResponse find(String url, SeekableStream body, Object headers = {}) async;
/*! @brief 用 FIND 方法请求指定的 url,并返回结果,等同于 request("PATCH", ...)
@param url 指定 url,必须是包含主机的完整 url
@param body 指定发送的 body 内容
@param headers 指定附加的 http 头,缺省无附加头
@return 返回服务器响应
*/
HttpResponse find(String url, Buffer body, Object headers = {}) async;
/*! @brief 用 FIND 方法请求指定的 url,并返回结果,等同于 request("PATCH", ...)
@param url 指定 url,必须是包含主机的完整 url
@param headers 指定附加的 http 头,缺省无附加头
@return 返回服务器响应
*/
HttpResponse find(String url, Object headers = {}) async;
};
View
@@ -194,4 +194,17 @@ interface Routing : Handler
@return 返回路由对象本身
*/
Routing patch(String pattern, Handler hdlr);
/*! @brief 添加一组 FIND 方法路由规则
@param map 路由参数
@return 返回路由对象本身
*/
Routing find(Object map);
/*! @brief 添加一条接受 http FIND 方法路由规则
@param pattern 消息匹配格式
@param hdlr 内置消息处理器,处理函数,链式处理数组,路由对象,详见 mq.Handler
@return 返回路由对象本身
*/
Routing find(String pattern, Handler hdlr);
};
View
@@ -176,4 +176,27 @@ module http
@return 返回服务器响应
*/
static HttpResponse patch(String url, Object headers = {}) async;
/*! @brief 用 FIND 方法请求指定的 url,并返回结果,等同于 request("PATCH", ...)
@param url 指定 url,必须是包含主机的完整 url
@param body 指定发送的 body 内容
@param headers 指定附加的 http 头,缺省无附加头
@return 返回服务器响应
*/
static HttpResponse find(String url, SeekableStream body, Object headers = {}) async;
/*! @brief 用 FIND 方法请求指定的 url,并返回结果,等同于 request("PATCH", ...)
@param url 指定 url,必须是包含主机的完整 url
@param body 指定发送的 body 内容
@param headers 指定附加的 http 头,缺省无附加头
@return 返回服务器响应
*/
static HttpResponse find(String url, Buffer body, Object headers = {}) async;
/*! @brief 用 FIND 方法请求指定的 url,并返回结果,等同于 request("PATCH", ...)
@param url 指定 url,必须是包含主机的完整 url
@param headers 指定附加的 http 头,缺省无附加头
@return 返回服务器响应
*/
static HttpResponse find(String url, Object headers = {}) async;
};

0 comments on commit b7f14b1

Please sign in to comment.