Permalink
Browse files

http, refactor: use Object to pass headers.

  • Loading branch information...
xicilion committed Sep 27, 2017
1 parent a3cfcc5 commit 731c1fdb9d824653fa49333156ef314957102389
@@ -26,9 +26,9 @@ class HttpCollection : public HttpCollection_base {
virtual result_t has(exlib::string name, bool& retVal);
virtual result_t first(exlib::string name, Variant& retVal);
virtual result_t all(exlib::string name, obj_ptr<List_base>& retVal);
virtual result_t add(Map_base* map);
virtual result_t add(v8::Local<v8::Object> map);
virtual result_t add(exlib::string name, Variant value);
virtual result_t set(Map_base* map);
virtual result_t set(v8::Local<v8::Object> map);
virtual result_t set(exlib::string name, Variant value);
virtual result_t remove(exlib::string name);
virtual result_t _named_getter(exlib::string property, Variant& retVal);
@@ -48,9 +48,9 @@ class HttpMessage : public Message {
result_t hasHeader(exlib::string name, bool& retVal);
result_t firstHeader(exlib::string name, Variant& retVal);
result_t allHeader(exlib::string name, obj_ptr<List_base>& retVal);
result_t addHeader(Map_base* map);
result_t addHeader(v8::Local<v8::Object> map);
result_t addHeader(exlib::string name, Variant value);
result_t setHeader(Map_base* map);
result_t setHeader(v8::Local<v8::Object> map);
result_t setHeader(exlib::string name, Variant value);
result_t removeHeader(exlib::string name);
result_t get_stream(obj_ptr<Stream_base>& retVal);
@@ -9,6 +9,7 @@
#include "HttpMessage.h"
#include "HttpResponse.h"
#include "HttpCollection.h"
#include "Map.h"
#ifndef HTTPREQUEST_H_
#define HTTPREQUEST_H_
@@ -68,9 +69,9 @@ class HttpRequest : public HttpRequest_base {
virtual result_t hasHeader(exlib::string name, bool& retVal);
virtual result_t firstHeader(exlib::string name, Variant& retVal);
virtual result_t allHeader(exlib::string name, obj_ptr<List_base>& retVal);
virtual result_t addHeader(Map_base* map);
virtual result_t addHeader(v8::Local<v8::Object> map);
virtual result_t addHeader(exlib::string name, Variant value);
virtual result_t setHeader(Map_base* map);
virtual result_t setHeader(v8::Local<v8::Object> map);
virtual result_t setHeader(exlib::string name, Variant value);
virtual result_t removeHeader(exlib::string name);
@@ -87,6 +88,11 @@ class HttpRequest : public HttpRequest_base {
virtual result_t get_query(obj_ptr<HttpCollection_base>& retVal);
public:
result_t addHeader(Map_base* map)
{
return ((Map*)map)->map(this, &HttpRequest::addHeader);
}
void header(const char* name, exlib::string& retVal)
{
Variant varCookie;
@@ -67,9 +67,9 @@ class HttpResponse : public HttpResponse_base {
virtual result_t hasHeader(exlib::string name, bool& retVal);
virtual result_t firstHeader(exlib::string name, Variant& retVal);
virtual result_t allHeader(exlib::string name, obj_ptr<List_base>& retVal);
virtual result_t addHeader(Map_base* map);
virtual result_t addHeader(v8::Local<v8::Object> map);
virtual result_t addHeader(exlib::string name, Variant value);
virtual result_t setHeader(Map_base* map);
virtual result_t setHeader(v8::Local<v8::Object> map);
virtual result_t setHeader(exlib::string name, Variant value);
virtual result_t removeHeader(exlib::string name);
@@ -26,9 +26,9 @@ class HttpUploadCollection : public HttpCollection_base {
virtual result_t has(exlib::string name, bool& retVal);
virtual result_t first(exlib::string name, Variant& retVal);
virtual result_t all(exlib::string name, obj_ptr<List_base>& retVal);
virtual result_t add(Map_base* map);
virtual result_t add(v8::Local<v8::Object> map);
virtual result_t add(exlib::string name, Variant value);
virtual result_t set(Map_base* map);
virtual result_t set(v8::Local<v8::Object> map);
virtual result_t set(exlib::string name, Variant value);
virtual result_t remove(exlib::string name);
virtual result_t _named_getter(exlib::string property, Variant& retVal);
@@ -17,7 +17,6 @@
namespace fibjs {
class List_base;
class Map_base;
class HttpCollection_base : public object_base {
DECLARE_CLASS(HttpCollection_base);
@@ -28,9 +27,9 @@ class HttpCollection_base : public object_base {
virtual result_t has(exlib::string name, bool& retVal) = 0;
virtual result_t first(exlib::string name, Variant& retVal) = 0;
virtual result_t all(exlib::string name, obj_ptr<List_base>& retVal) = 0;
virtual result_t add(Map_base* map) = 0;
virtual result_t add(v8::Local<v8::Object> map) = 0;
virtual result_t add(exlib::string name, Variant value) = 0;
virtual result_t set(Map_base* map) = 0;
virtual result_t set(v8::Local<v8::Object> map) = 0;
virtual result_t set(exlib::string name, Variant value) = 0;
virtual result_t remove(exlib::string name) = 0;
virtual result_t _named_getter(exlib::string property, Variant& retVal) = 0;
@@ -65,7 +64,6 @@ class HttpCollection_base : public object_base {
}
#include "List.h"
#include "Map.h"
namespace fibjs {
inline ClassInfo& HttpCollection_base::class_info()
@@ -161,7 +159,7 @@ inline void HttpCollection_base::s_add(const v8::FunctionCallbackInfo<v8::Value>
METHOD_OVER(1, 1);
ARG(obj_ptr<Map_base>, 0);
ARG(v8::Local<v8::Object>, 0);
hr = pInst->add(v0);
@@ -182,7 +180,7 @@ inline void HttpCollection_base::s_set(const v8::FunctionCallbackInfo<v8::Value>
METHOD_OVER(1, 1);
ARG(obj_ptr<Map_base>, 0);
ARG(v8::Local<v8::Object>, 0);
hr = pInst->set(v0);
@@ -21,7 +21,6 @@ class Message_base;
class HttpCollection_base;
class Stream_base;
class List_base;
class Map_base;
class HttpMessage_base : public Message_base {
DECLARE_CLASS(HttpMessage_base);
@@ -43,9 +42,9 @@ class HttpMessage_base : public Message_base {
virtual result_t hasHeader(exlib::string name, bool& retVal) = 0;
virtual result_t firstHeader(exlib::string name, Variant& retVal) = 0;
virtual result_t allHeader(exlib::string name, obj_ptr<List_base>& retVal) = 0;
virtual result_t addHeader(Map_base* map) = 0;
virtual result_t addHeader(v8::Local<v8::Object> map) = 0;
virtual result_t addHeader(exlib::string name, Variant value) = 0;
virtual result_t setHeader(Map_base* map) = 0;
virtual result_t setHeader(v8::Local<v8::Object> map) = 0;
virtual result_t setHeader(exlib::string name, Variant value) = 0;
virtual result_t removeHeader(exlib::string name) = 0;
@@ -85,7 +84,6 @@ class HttpMessage_base : public Message_base {
#include "HttpCollection.h"
#include "Stream.h"
#include "List.h"
#include "Map.h"
namespace fibjs {
inline ClassInfo& HttpMessage_base::class_info()
@@ -313,7 +311,7 @@ inline void HttpMessage_base::s_addHeader(const v8::FunctionCallbackInfo<v8::Val
METHOD_OVER(1, 1);
ARG(obj_ptr<Map_base>, 0);
ARG(v8::Local<v8::Object>, 0);
hr = pInst->addHeader(v0);
@@ -334,7 +332,7 @@ inline void HttpMessage_base::s_setHeader(const v8::FunctionCallbackInfo<v8::Val
METHOD_OVER(1, 1);
ARG(obj_ptr<Map_base>, 0);
ARG(v8::Local<v8::Object>, 0);
hr = pInst->setHeader(v0);
@@ -234,9 +234,18 @@ result_t HttpCollection::add(exlib::string name, Variant value)
return 0;
}
result_t HttpCollection::add(Map_base* map)
result_t HttpCollection::add(v8::Local<v8::Object> map)
{
return ((Map*)map)->map(this, &HttpCollection::add);
v8::Local<v8::Array> ks = map->GetPropertyNames();
int32_t len = ks->Length();
int32_t i;
for (i = 0; i < len; i++) {
v8::Local<v8::Value> k = ks->Get(i);
add(*v8::String::Utf8Value(k), map->Get(k));
}
return 0;
}
result_t HttpCollection::set(exlib::string name, Variant value)
@@ -275,9 +284,18 @@ result_t HttpCollection::set(exlib::string name, Variant value)
return 0;
}
result_t HttpCollection::set(Map_base* map)
result_t HttpCollection::set(v8::Local<v8::Object> map)
{
return ((Map*)map)->map(this, &HttpCollection::set);
v8::Local<v8::Array> ks = map->GetPropertyNames();
int32_t len = ks->Length();
int32_t i;
for (i = 0; i < len; i++) {
v8::Local<v8::Value> k = ks->Get(i);
set(*v8::String::Utf8Value(k), map->Get(k));
}
return 0;
}
result_t HttpCollection::remove(exlib::string name)
@@ -552,7 +552,7 @@ result_t HttpMessage::allHeader(exlib::string name, obj_ptr<List_base>& retVal)
return m_headers->all(name, retVal);
}
result_t HttpMessage::addHeader(Map_base* map)
result_t HttpMessage::addHeader(v8::Local<v8::Object> map)
{
return m_headers->add(map);
}
@@ -562,7 +562,7 @@ result_t HttpMessage::addHeader(exlib::string name, Variant value)
return m_headers->add(name, value);
}
result_t HttpMessage::setHeader(Map_base* map)
result_t HttpMessage::setHeader(v8::Local<v8::Object> map)
{
return m_headers->set(map);
}
@@ -134,7 +134,7 @@ result_t HttpRequest::allHeader(exlib::string name, obj_ptr<List_base>& retVal)
return m_message->allHeader(name, retVal);
}
result_t HttpRequest::addHeader(Map_base* map)
result_t HttpRequest::addHeader(v8::Local<v8::Object> map)
{
return m_message->addHeader(map);
}
@@ -144,7 +144,7 @@ result_t HttpRequest::addHeader(exlib::string name, Variant value)
return m_message->addHeader(name, value);
}
result_t HttpRequest::setHeader(Map_base* map)
result_t HttpRequest::setHeader(v8::Local<v8::Object> map)
{
return m_message->setHeader(map);
}
@@ -135,7 +135,7 @@ result_t HttpResponse::allHeader(exlib::string name, obj_ptr<List_base>& retVal)
return m_message->allHeader(name, retVal);
}
result_t HttpResponse::addHeader(Map_base* map)
result_t HttpResponse::addHeader(v8::Local<v8::Object> map)
{
return m_message->addHeader(map);
}
@@ -145,7 +145,7 @@ result_t HttpResponse::addHeader(exlib::string name, Variant value)
return m_message->addHeader(name, value);
}
result_t HttpResponse::setHeader(Map_base* map)
result_t HttpResponse::setHeader(v8::Local<v8::Object> map)
{
return m_message->setHeader(map);
}
@@ -264,9 +264,18 @@ result_t HttpUploadCollection::add(exlib::string name, Variant value)
return 0;
}
result_t HttpUploadCollection::add(Map_base* map)
result_t HttpUploadCollection::add(v8::Local<v8::Object> map)
{
return ((Map*)map)->map(this, &HttpUploadCollection::add);
v8::Local<v8::Array> ks = map->GetPropertyNames();
int32_t len = ks->Length();
int32_t i;
for (i = 0; i < len; i++) {
v8::Local<v8::Value> k = ks->Get(i);
add(*v8::String::Utf8Value(k), map->Get(k));
}
return 0;
}
result_t HttpUploadCollection::set(exlib::string name, Variant value)
@@ -301,9 +310,18 @@ result_t HttpUploadCollection::set(exlib::string name, Variant value)
return 0;
}
result_t HttpUploadCollection::set(Map_base* map)
result_t HttpUploadCollection::set(v8::Local<v8::Object> map)
{
return ((Map*)map)->map(this, &HttpUploadCollection::set);
v8::Local<v8::Array> ks = map->GetPropertyNames();
int32_t len = ks->Length();
int32_t i;
for (i = 0; i < len; i++) {
v8::Local<v8::Value> k = ks->Get(i);
set(*v8::String::Utf8Value(k), map->Get(k));
}
return 0;
}
result_t HttpUploadCollection::remove(exlib::string name)
@@ -26,7 +26,7 @@ interface HttpCollection : object
/*! @brief 添加一个键值数据,添加数据并不修改已存在的键值的数据
@param map 指定要添加的键值数据字典
*/
add(Map map);
add(Object map);
/*! @brief 添加一个键值数据,添加数据并不修改已存在的键值的数据
@param name 指定要添加的键值
@@ -37,7 +37,7 @@ interface HttpCollection : object
/*! @brief 设定一个键值数据,设定数据将修改键值所对应的第一个数值,并清除相同键值的其余数据
@param map 指定要设定的键值数据字典
*/
set(Map map);
set(Object map);
/*! @brief 设定一个键值数据,设定数据将修改键值所对应的第一个数值,并清除相同键值的其余数据
@param name 指定要设定的键值
@@ -44,7 +44,7 @@ interface HttpMessage : Message
/*! @brief 添加一个消息头,添加数据并不修改已存在的键值的消息头
@param map 指定要添加的键值数据字典
*/
addHeader(Map map);
addHeader(Object map);
/*! @brief 添加一个消息头,添加数据并不修改已存在的键值的消息头
@param name 指定要添加的键值
@@ -55,7 +55,7 @@ interface HttpMessage : Message
/*! @brief 设定一个消息头,设定数据将修改键值所对应的第一个数值,并清除相同键值的其余消息头
@param map 指定要设定的键值数据字典
*/
setHeader(Map map);
setHeader(Object map);
/*! @brief 设定一个消息头,设定数据将修改键值所对应的第一个数值,并清除相同键值的其余消息头
@param name 指定要设定的键值

0 comments on commit 731c1fd

Please sign in to comment.