Put and Post are now functional
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#define ksuccess_get_body "{\"status\":\"ok\"}"
|
||||
#define ksuccess_delete_body "{\"status\":\"delete\"}"
|
||||
#define ksuccess_put_body "{\"status\":\"put\"}"
|
||||
#define ksuccess_post_body "{\"status\":\"post\"}"
|
||||
#define kerror_body "{\"status\":\"error\"}"
|
||||
|
||||
#define kserver_port "7777"
|
||||
@@ -74,7 +75,10 @@ int my_success_rest_delete_handler(struct evhttp_request *req, void *arg)
|
||||
|
||||
int my_success_rest_put_handler(struct evhttp_request *req, void *arg)
|
||||
{
|
||||
restd_http_response(req, 200, "application/json", ksuccess_put_body);
|
||||
char *body;
|
||||
body = restd_http_get_body(req);
|
||||
restd_http_response(req, 200, "application/json", body);
|
||||
free(body);
|
||||
return RESTD_OK;
|
||||
}
|
||||
|
||||
@@ -82,7 +86,10 @@ int my_success_rest_put_handler(struct evhttp_request *req, void *arg)
|
||||
|
||||
int my_success_rest_post_handler(struct evhttp_request *req, void *arg)
|
||||
{
|
||||
restd_http_response(req, 200, "application/json", ksuccess_put_body);
|
||||
char *body;
|
||||
body = restd_http_get_body(req);
|
||||
restd_http_response(req, 200, "application/json", body);
|
||||
free(body);
|
||||
return RESTD_OK;
|
||||
}
|
||||
|
||||
@@ -148,11 +155,14 @@ int exec_request(const char *request, const char *path, int expected_code, const
|
||||
{
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 0);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_CUSTOMREQUEST, kput_method);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDSIZE, strlen(expected_body));
|
||||
curl_easy_setopt(curl_handle, CURLOPT_COPYPOSTFIELDS, expected_body);
|
||||
}
|
||||
else if (strcmp(request, kpost_method) == 0)
|
||||
{
|
||||
printf("method POST\n");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_POST, 0);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDSIZE, strlen(expected_body));
|
||||
curl_easy_setopt(curl_handle, CURLOPT_COPYPOSTFIELDS, expected_body);
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 2);
|
||||
@@ -392,7 +402,6 @@ TEST("Rest - create start access http hook free\t")
|
||||
restd_server_set_option(rest_server, "server.port", kserver_port);
|
||||
restd_server_set_option(rest_server, "server.thread", "1");
|
||||
|
||||
// restd_server_register_hook(rest_server, restd_http_handler, NULL);
|
||||
restd_server_register_hook_on_path(rest_server, EVHTTP_REQ_GET, kapi_test_get, my_success_http_handler, NULL);
|
||||
|
||||
ret = restd_server_start(rest_server);
|
||||
@@ -444,7 +453,9 @@ TEST("Rest - create start access rest hook free\t")
|
||||
ret = exec_request(kput_method, "http://localhost:" kserver_port kapi_test_get, 200, ksuccess_put_body);
|
||||
ASSERT_EQUAL_INT(ret, 0);
|
||||
|
||||
// TODO POST
|
||||
PRINTLN("\n - POST");
|
||||
ret = exec_request(kpost_method, "http://localhost:" kserver_port kapi_test_get, 200, ksuccess_post_body);
|
||||
ASSERT_EQUAL_INT(ret, 0);
|
||||
|
||||
restd_server_free(rest_server);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user