diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-01-21 10:33:44 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-01-21 10:33:44 +0100 |
commit | 52a5e465844add3dd968f2318eab5e6f91a5a1e7 (patch) | |
tree | 456561899f7df6d0056deee9ce4c507a30c05abd /doc/examples | |
parent | 9131da3340181d97d9deca4403a4bcd3d59236a4 (diff) | |
download | libmicrohttpd-52a5e465844add3dd968f2318eab5e6f91a5a1e7.tar.gz libmicrohttpd-52a5e465844add3dd968f2318eab5e6f91a5a1e7.zip |
use correct HTTP header (content type, not content encoding) for mime type in example; do check return value in example
Diffstat (limited to 'doc/examples')
-rw-r--r-- | doc/examples/responseheaders.c | 18 | ||||
-rw-r--r-- | doc/examples/sessions.c | 60 |
2 files changed, 58 insertions, 20 deletions
diff --git a/doc/examples/responseheaders.c b/doc/examples/responseheaders.c index 30ac4596..cddcaa66 100644 --- a/doc/examples/responseheaders.c +++ b/doc/examples/responseheaders.c | |||
@@ -63,9 +63,21 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, | |||
63 | return MHD_NO; | 63 | return MHD_NO; |
64 | } | 64 | } |
65 | response = | 65 | response = |
66 | MHD_create_response_from_fd_at_offset64 ((size_t) sbuf.st_size, fd, 0); | 66 | MHD_create_response_from_fd_at_offset64 ((size_t) sbuf.st_size, |
67 | MHD_add_response_header (response, "Content-Type", MIMETYPE); | 67 | fd, |
68 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 68 | 0); |
69 | if (MHD_YES != | ||
70 | MHD_add_response_header (response, | ||
71 | MHD_HTTP_HEADER_CONTENT_TYPE, | ||
72 | MIMETYPE)) | ||
73 | { | ||
74 | fprintf (stderr, | ||
75 | "Failed to set content encoding type!\n"); | ||
76 | /* return response without content encoding anyway ... */ | ||
77 | } | ||
78 | ret = MHD_queue_response (connection, | ||
79 | MHD_HTTP_OK, | ||
80 | response); | ||
69 | MHD_destroy_response (response); | 81 | MHD_destroy_response (response); |
70 | 82 | ||
71 | return ret; | 83 | return ret; |
diff --git a/doc/examples/sessions.c b/doc/examples/sessions.c index 958a775f..0544a2d7 100644 --- a/doc/examples/sessions.c +++ b/doc/examples/sessions.c | |||
@@ -270,9 +270,15 @@ serve_simple_form (const void *cls, | |||
270 | /* return static form */ | 270 | /* return static form */ |
271 | response = MHD_create_response_from_buffer_static (strlen (form), form); | 271 | response = MHD_create_response_from_buffer_static (strlen (form), form); |
272 | add_session_cookie (session, response); | 272 | add_session_cookie (session, response); |
273 | MHD_add_response_header (response, | 273 | if (MHD_YES != |
274 | MHD_HTTP_HEADER_CONTENT_ENCODING, | 274 | MHD_add_response_header (response, |
275 | mime); | 275 | MHD_HTTP_HEADER_CONTENT_TYPE, |
276 | mime)) | ||
277 | { | ||
278 | fprintf (stderr, | ||
279 | "Failed to set content type header!\n"); | ||
280 | /* return response without content type anyway ... */ | ||
281 | } | ||
276 | ret = MHD_queue_response (connection, | 282 | ret = MHD_queue_response (connection, |
277 | MHD_HTTP_OK, | 283 | MHD_HTTP_OK, |
278 | response); | 284 | response); |
@@ -327,9 +333,15 @@ fill_v1_form (const void *cls, | |||
327 | if (NULL != response) | 333 | if (NULL != response) |
328 | { | 334 | { |
329 | add_session_cookie (session, response); | 335 | add_session_cookie (session, response); |
330 | MHD_add_response_header (response, | 336 | if (MHD_YES != |
331 | MHD_HTTP_HEADER_CONTENT_ENCODING, | 337 | MHD_add_response_header (response, |
332 | mime); | 338 | MHD_HTTP_HEADER_CONTENT_TYPE, |
339 | mime)) | ||
340 | { | ||
341 | fprintf (stderr, | ||
342 | "Failed to set content type header!\n"); | ||
343 | /* return response without content type anyway ... */ | ||
344 | } | ||
333 | ret = MHD_queue_response (connection, | 345 | ret = MHD_queue_response (connection, |
334 | MHD_HTTP_OK, | 346 | MHD_HTTP_OK, |
335 | response); | 347 | response); |
@@ -392,9 +404,15 @@ fill_v1_v2_form (const void *cls, | |||
392 | if (NULL != response) | 404 | if (NULL != response) |
393 | { | 405 | { |
394 | add_session_cookie (session, response); | 406 | add_session_cookie (session, response); |
395 | MHD_add_response_header (response, | 407 | if (MHD_YES != |
396 | MHD_HTTP_HEADER_CONTENT_ENCODING, | 408 | MHD_add_response_header (response, |
397 | mime); | 409 | MHD_HTTP_HEADER_CONTENT_TYPE, |
410 | mime)) | ||
411 | { | ||
412 | fprintf (stderr, | ||
413 | "Failed to set content type header!\n"); | ||
414 | /* return response without content type anyway ... */ | ||
415 | } | ||
398 | ret = MHD_queue_response (connection, | 416 | ret = MHD_queue_response (connection, |
399 | MHD_HTTP_OK, | 417 | MHD_HTTP_OK, |
400 | response); | 418 | response); |
@@ -434,9 +452,15 @@ not_found_page (const void *cls, | |||
434 | ret = MHD_queue_response (connection, | 452 | ret = MHD_queue_response (connection, |
435 | MHD_HTTP_NOT_FOUND, | 453 | MHD_HTTP_NOT_FOUND, |
436 | response); | 454 | response); |
437 | MHD_add_response_header (response, | 455 | if (MHD_YES != |
438 | MHD_HTTP_HEADER_CONTENT_ENCODING, | 456 | MHD_add_response_header (response, |
439 | mime); | 457 | MHD_HTTP_HEADER_CONTENT_TYPE, |
458 | mime)) | ||
459 | { | ||
460 | fprintf (stderr, | ||
461 | "Failed to set content type header!\n"); | ||
462 | /* return response without content type anyway ... */ | ||
463 | } | ||
440 | MHD_destroy_response (response); | 464 | MHD_destroy_response (response); |
441 | return ret; | 465 | return ret; |
442 | } | 466 | } |
@@ -470,8 +494,8 @@ static const struct Page pages[] = { | |||
470 | * specified offset | 494 | * specified offset |
471 | * @param off offset of data in the overall value | 495 | * @param off offset of data in the overall value |
472 | * @param size number of bytes in data available | 496 | * @param size number of bytes in data available |
473 | * @return MHD_YES to continue iterating, | 497 | * @return #MHD_YES to continue iterating, |
474 | * MHD_NO to abort the iteration | 498 | * #MHD_NO to abort the iteration |
475 | */ | 499 | */ |
476 | static enum MHD_Result | 500 | static enum MHD_Result |
477 | post_iterator (void *cls, | 501 | post_iterator (void *cls, |
@@ -615,9 +639,11 @@ create_response (void *cls, | |||
615 | if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) | 639 | if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) |
616 | { | 640 | { |
617 | /* evaluate POST data */ | 641 | /* evaluate POST data */ |
618 | MHD_post_process (request->pp, | 642 | if (MHD_YES != |
619 | upload_data, | 643 | MHD_post_process (request->pp, |
620 | *upload_data_size); | 644 | upload_data, |
645 | *upload_data_size)) | ||
646 | return MHD_NO; /* internal error */ | ||
621 | if (0 != *upload_data_size) | 647 | if (0 != *upload_data_size) |
622 | { | 648 | { |
623 | *upload_data_size = 0; | 649 | *upload_data_size = 0; |