Skip to content

Commit 8fc1479

Browse files
author
Chrono Law
committed
Merge branch 'master' of github.com:chronolaw/ngx_cpp_dev
2 parents fbe731a + a3be417 commit 8fc1479

File tree

5 files changed

+96
-3
lines changed

5 files changed

+96
-3
lines changed

modules/subrequest/NdgSubrequestConf.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class NdgSubrequestConf final
2828
auto prev = reinterpret_cast<this_type*>(parent);
2929
auto conf = reinterpret_cast<this_type*>(child);
3030

31-
NgxValue::merge(conf->loc, prev->loc, ngx_string("/echo"));
32-
NgxValue::merge(conf->args, prev->args, ngx_null_string);
31+
NgxValue::merge(conf->loc, prev->loc, ngx_str_t ngx_string("/echo"));
32+
NgxValue::merge(conf->args, prev->args, ngx_str_t ngx_null_string);
3333

3434
return NGX_CONF_OK;
3535
}

ngxpp/NgxEvent.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ class NgxEvent final : public NgxWrapper<ngx_event_t>
2020
~NgxEvent() = default;
2121
public:
2222
template<typename T>
23-
void data(T *p) const
23+
void data(T* p) const
2424
{
2525
get()->data = p;
2626
}
2727

28+
template<typename T>
29+
void data(T& v) const
30+
{
31+
get()->data = &v;
32+
}
33+
2834
template<typename T>
2935
T& data() const
3036
{

ngxpp/NgxHeaders.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class NgxHeaders final : public NgxWrapper<T>
5959

6060
return p->value;
6161
}
62+
63+
ngx_str_t operator[](const char* key) const
64+
{
65+
return operator[](string_ref_type(key));
66+
}
6267
public:
6368
void add(const kv_type& kv) const
6469
{

ngxpp/NgxModule.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ class NgxModuleConfig final
8686
return get<T3>(ctx(cf)->loc_conf);
8787
}
8888

89+
public:
90+
// cycle->conf_ccycle->conf_ctxtx[ngx_http_module.index] must not null
91+
META_TYPE(T1) main(ngx_cycle_t* cycle) const
92+
{
93+
return get<T1>(ctx(cycle)->main_conf);
94+
}
95+
96+
ngx_http_conf_ctx_t* ctx(ngx_cycle_t* cycle) const
97+
{
98+
return reinterpret_cast<ngx_http_conf_ctx_t*>(cycle->conf_ctx[ngx_http_module.index]);
99+
}
89100
private:
90101
ngx_http_conf_ctx_t* ctx(ngx_conf_t* cf) const
91102
{

ngxpp/NgxRequest.hpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ class NgxRequest final : public NgxWrapper<ngx_http_request_t>
7878
{
7979
return m_body;
8080
}
81+
public:
82+
ngx_str_t arg(const ngx_str_t& name) const
83+
{
84+
ngx_str_t value = ngx_null_string;
85+
86+
ngx_http_arg(get(), name.data, name.len, &value);
87+
88+
return value;
89+
}
90+
public:
91+
void finalize(ngx_int_t rc = NGX_HTTP_INTERNAL_SERVER_ERROR) const
92+
{
93+
ngx_http_finalize_request(get(), rc);
94+
}
8195
private:
8296
headers_type m_headers;
8397
body_type m_body;
@@ -113,6 +127,34 @@ class NgxResponse final : public NgxWrapper<ngx_http_request_t>
113127
headers()->content_length_n = len;
114128
}
115129

130+
public:
131+
ngx_uint_t status() const
132+
{
133+
return headers()->status;
134+
}
135+
136+
off_t length() const
137+
{
138+
return headers()->content_length_n;
139+
}
140+
public:
141+
void set_content_type() const
142+
{
143+
auto rc = ngx_http_set_content_type(get());
144+
145+
NgxException::require(rc);
146+
}
147+
148+
void clear_content_length() const
149+
{
150+
ngx_http_clear_content_length(get());
151+
}
152+
153+
void clear_accept_ranges() const
154+
{
155+
ngx_http_clear_accept_ranges(get());
156+
}
157+
116158
public:
117159
ngx_int_t send() const
118160
{
@@ -199,5 +241,34 @@ class NgxResponse final : public NgxWrapper<ngx_http_request_t>
199241
NgxPool m_pool;
200242
};
201243

244+
class NgxRequestCleanup final : public NgxWrapper<ngx_http_request_t>
245+
{
246+
public:
247+
typedef NgxWrapper<ngx_http_request_t> super_type;
248+
typedef NgxRequestCleanup this_type;
249+
public:
250+
NgxRequestCleanup(ngx_http_request_t* r):super_type(r)
251+
{}
252+
253+
~NgxRequestCleanup() = default;
254+
public:
255+
template<typename F>
256+
ngx_http_cleanup_t* add(F f, std::size_t n = 0) const
257+
{
258+
auto cln = ngx_http_cleanup_add(get(), n);
259+
260+
NgxException::require(cln);
261+
262+
cln->handler = f;
263+
264+
if(!n)
265+
{
266+
cln->data = get();
267+
}
268+
269+
return cln;
270+
}
271+
};
272+
202273
#endif //_NGX_HTTP_REQUEST_HPP
203274

0 commit comments

Comments
 (0)