8000 http, refactor: cache STATUS_CODES in Isolate. · fibjs/fibjs@8b2def9 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 8b2def9

Browse files
committed
http, refactor: cache STATUS_CODES in Isolate.
1 parent a5e9b5a commit 8b2def9

File tree

5 files changed

+16
-7
lines changed
  • fibjs
    • include
  • src/http
  • idl/zh-cn
  • npm/types/dts/module
  • 5 files changed

    +16
    -7
    lines changed

    fibjs/include/Isolate.h

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -265,6 +265,7 @@ class Isolate : public exlib::linkitem {
    265265
    bool m_intask = false;
    266266

    267267
    obj_ptr<HttpClient> m_httpclient;
    268+
    v8::Global<v8::Object> STATUS_CODES;
    268269

    269270
    obj_ptr<Stream_base> m_stdio[3];
    270271

    fibjs/include/ifs/http.h

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -34,7 +34,7 @@ class http_base : public object_base {
    3434

    3535
    public:
    3636
    // http_base
    37-
    static result_t get_STATUS_CODES(v8::Local<v8::Array>& retVal);
    37+
    static result_t get_STATUS_CODES(v8::Local<v8::Object>& retVal);
    3838
    static result_t get_cookies(obj_ptr<NArray>& retVal);
    3939
    static result_t get_timeout(int32_t& retVal);
    4040
    static result_t set_timeout(int32_t newVal);
    @@ -202,7 +202,7 @@ inline ClassInfo& http_base::class_info()
    202202

    203203
    inline void http_base::s_static_get_STATUS_CODES(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args)
    204204
    {
    205-
    v8::Local<v8::Array> vr;
    205+
    v8::Local<v8::Object> vr;
    206206

    207207
    PROPERTY_ENTER();
    208208

    fibjs/src/http/HttpResponse.cpp

    Lines changed: 11 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -284,15 +284,23 @@ static class _init_status_line {
    284284
    }
    285285
    } s_init_status_line;
    286286

    287-
    result_t http_base::get_STATUS_CODES(v8::Local<v8::Array>& retVal)
    287+
    result_t http_base::get_STATUS_CODES(v8::Local<v8::Object>& retVal)
    288288
    {
    289289
    Isolate* isolate = Isolate::current();
    290290
    v8::Local<v8::Context> context = isolate->context();
    291291
    int32_t i;
    292292

    293-
    retVal = v8::Array::New(isolate->m_isolate);
    293+
    if (!isolate->STATUS_CODES.IsEmpty()) {
    294+
    retVal = isolate->STATUS_CODES.Get(isolate->m_isolate);
    295+
    return 0;
    296+
    }
    297+
    298+
    v8::Local<v8::Object> o = v8::Object::New(isolate->m_isolate);
    294299
    for (i = 0; i < RESPONSE_CODES; i++)
    295-
    retVal->Set(context, atoi(status_lines[i]), isolate->NewString(status_lines[i] + 5)).IsJust();
    300+
    o->Set(context, isolate->NewString(status_lines[i] + 1, 3), isolate->NewString(status_lines[i] + 5)).IsJust();
    301+
    302+
    isolate->STATUS_CODES.Reset(isolate->m_isolate, o);
    303+
    retVal = o;
    296304

    297305
    return 0;
    298306
    }

    idl/zh-cn/http.idl

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -56,7 +56,7 @@ module http
    5656
    static HttpRepeater new Repeater();
    5757

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

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

    npm/types/dts/module/http.d.ts

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -89,7 +89,7 @@ declare module 'http' {
    8989
    /**
    9090
    * @description 返回标准的 HTTP 响应状态码的集合,以及各自的简短描述。
    9191
    */
    92-
    const STATUS_CODES: any[];
    92+
    const STATUS_CODES: FIBJS.GeneralObject;
    9393

    9494
    /**
    9595
    * @description 返回http客户端的 HttpCookie 对象列表

    0 commit comments

    Comments
     (0)
    0