Skip to content

Commit 38c7198

Browse files
author
Chrono Law
committed
req finalize&cleanup
1 parent 4916ed7 commit 38c7198

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

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)