Skip to content
Permalink
Browse files

http, feat: support http.STATUS_CODES.

  • Loading branch information...
xicilion committed Jun 18, 2018
1 parent e43fbf2 commit d6b7d8a1075b45fee91e86b234165b7fc0b7469c
Showing with 31 additions and 0 deletions.
  1. +15 −0 fibjs/include/ifs/http.h
  2. +13 −0 fibjs/src/http/HttpResponse.cpp
  3. +3 −0 idl/zh-cn/http.idl
@@ -31,6 +31,7 @@ class http_base : public object_base {

public:
// http_base
static result_t get_STATUS_CODES(v8::Local<v8::Array>& retVal);
static result_t get_cookies(obj_ptr<NArray>& retVal);
static result_t get_timeout(int32_t& retVal);
static result_t set_timeout(int32_t newVal);
@@ -63,6 +64,7 @@ class http_base : public object_base {
}

public:
static void s_get_STATUS_CODES(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_cookies(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_timeout(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_set_timeout(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args);
@@ -133,6 +135,7 @@ inline ClassInfo& http_base::class_info()
};

static ClassData::ClassProperty s_property[] = {
{ "STATUS_CODES", s_get_STATUS_CODES, block_set, true },
{ "cookies", s_get_cookies, block_set, true },
{ "timeout", s_get_timeout, s_set_timeout, true },
{ "enableCookie", s_get_enableCookie, s_set_enableCookie, true },
@@ -151,6 +154,18 @@ inline ClassInfo& http_base::class_info()
return s_ci;
}

inline void http_base::s_get_STATUS_CODES(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
v8::Local<v8::Array> vr;

METHOD_NAME("http.STATUS_CODES");
PROPERTY_ENTER();

hr = get_STATUS_CODES(vr);

METHOD_RETURN();
}

inline void http_base::s_get_cookies(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
obj_ptr<NArray> vr;
@@ -6,6 +6,7 @@
*/

#include "object.h"
#include "ifs/http.h"
#include "HttpResponse.h"
#include "HttpCookie.h"
#include "Buffer.h"
@@ -263,6 +264,18 @@ static class _init_status_line {
}
} s_init_status_line;

result_t http_base::get_STATUS_CODES(v8::Local<v8::Array>& retVal)
{
Isolate* isolate = Isolate::current();
int32_t i;

retVal = v8::Array::New(isolate->m_isolate);
for (i = 0; i < RESPONSE_CODES; i++)
retVal->Set(atoi(status_lines[i]), isolate->NewString(status_lines[i] + 5));

return 0;
}

result_t HttpResponse::sendTo(Stream_base* stm, AsyncEvent* ac)
{
if (ac->isSync())
@@ -23,6 +23,9 @@ module http
/*! @brief 创建一个 http 协议处理器对象,参见 HttpHandler */
static HttpHandler new Handler();

/*! @brief 返回标准的 HTTP 响应状态码的集合,以及各自的简短描述。 */
static readonly Array STATUS_CODES;

/*! @brief 返回http客户端的 HttpCookie 对象列表 */
static readonly NArray cookies;

0 comments on commit d6b7d8a

Please sign in to comment.
You can’t perform that action at this time.