aboutsummaryrefslogtreecommitdiff
path: root/examples/append.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/append.c')
-rw-r--r--examples/append.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/examples/append.c b/examples/append.c
index 3320fe0..e6e4a8a 100644
--- a/examples/append.c
+++ b/examples/append.c
@@ -7,6 +7,13 @@
void response_request(struct magi_request * req, struct magi_response * res)
{
+ char * data = magi_param_list_get(req->params, "addon");
+ if (data) {
+ FILE * file = fopen("file_to_append", "a");
+ fputs(data, file);
+ fclose(file);
+ }
+
magi_response_content_type(res, magi_xhtml);
magi_response_add(
res,
@@ -15,19 +22,12 @@ void response_request(struct magi_request * req, struct magi_response * res)
"<html xmlns='http://www.w3.org/1999/xhtml'>"
"<head><title>Append to File</title></head>"
"<body>"
- "<form action='/cgi-bin/append' method='get'><fieldset>"
+ "<form action='/cgi-bin/append' method='post'><fieldset>"
"<input type='text' name='addon' value='Whatever you want to add.'/>"
"<input type='submit' value='Append'/>"
"</fieldset></form>"
"</body>"
"</html>");
-
- struct magi_param * addon = magi_param_list_get(req->url_params, "addon");
- if (addon && addon->data) {
- FILE * file = fopen("file_to_append", "a");
- fputs(addon->data, file);
- fclose(file);
- }
}
int main(int argc, char const * argv[])
@@ -36,6 +36,7 @@ int main(int argc, char const * argv[])
magi_request_setup(&request);
if (magi_request_cgi(&request)) {
struct magi_response response;
+ magi_response_setup(&response);
response_request(&request, &response);
magi_response_cgi(&response);
magi_response_destroy(&response);