@@ -13,14 +13,13 @@ size_t writefunc(void *ptr, size_t size, size_t nmemb, std::string *s)
1313 return size*nmemb;
1414}
1515
16- size_t headerfunc ( void *ptr, size_t size, size_t nmemb, map<string, string>* ss)
16+ size_t headerfunc (void *ptr, size_t size, size_t nmemb, map<string, string>* ss)
1717{
1818 string s_ptr ((char *)ptr, size*nmemb);
1919 size_t pos = s_ptr.find (" :" );
2020 if (pos != string::npos)
21- {
22- (*ss)[s_ptr.substr (0 , pos)] = s_ptr.substr (pos + 2 , s_ptr.size () - pos - 4 );
23- }
21+ (*ss)[s_ptr.substr (0 , pos)] =
22+ s_ptr.substr (pos + 2 , s_ptr.size () - pos - 4 );
2423 return size*nmemb;
2524}
2625
@@ -31,6 +30,12 @@ class simple_resource : public http_resource
3130 {
3231 *res = new http_string_response (" OK" , 200 , " text/plain" );
3332 }
33+ virtual void render_POST (const http_request& req, http_response** res)
34+ {
35+ *res = new http_string_response (
36+ req.get_arg (" arg1" )+req.get_arg (" arg2" ), 200 , " text/plain"
37+ );
38+ }
3439};
3540
3641class header_test_resource : public http_resource
@@ -180,6 +185,23 @@ LT_BEGIN_AUTO_TEST(basic_suite, complete)
180185 curl_easy_cleanup (curl);
181186LT_END_AUTO_TEST (complete)
182187
188+ LT_BEGIN_AUTO_TEST(basic_suite, postprocessor)
189+ simple_resource* resource = new simple_resource();
190+ ws->register_resource (" base" , resource);
191+ curl_global_init (CURL_GLOBAL_ALL);
192+ std::string s;
193+ CURL *curl = curl_easy_init();
194+ CURLcode res;
195+ curl_easy_setopt (curl, CURLOPT_URL, " localhost:8080/base" );
196+ curl_easy_setopt (curl, CURLOPT_POSTFIELDS, " arg1=lib&arg2=httpserver" );
197+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc);
198+ curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s);
199+ res = curl_easy_perform(curl);
200+ LT_ASSERT_EQ (res, 0 );
201+ LT_CHECK_EQ (s, " libhttpserver" );
202+ curl_easy_cleanup (curl);
203+ LT_END_AUTO_TEST (postprocessor)
204+
183205
184206LT_BEGIN_AUTO_TEST_ENV()
185207 AUTORUN_TESTS()
0 commit comments