aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-08-08 15:08:22 +0200
committerChristian Grothoff <christian@grothoff.org>2017-08-08 15:08:22 +0200
commitf454457953a718c9306e06c595d614ce31e1d351 (patch)
treeb3b587ea246015060103bb634fc41408c267ca12
parent783c7bd4ed840e64cfdc30c926212d405f6d6b41 (diff)
downloadlibmicrohttpd-f454457953a718c9306e06c595d614ce31e1d351.tar.gz
libmicrohttpd-f454457953a718c9306e06c595d614ce31e1d351.zip
revisions based on discussions with EG
-rw-r--r--src/include/microhttpd2.h164
1 files changed, 132 insertions, 32 deletions
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h
index e97d748b..f4e6443c 100644
--- a/src/include/microhttpd2.h
+++ b/src/include/microhttpd2.h
@@ -798,16 +798,17 @@ typedef enum MHD_Bool
798/** 798/**
799 * Signature of the callback used by MHD to notify the application 799 * Signature of the callback used by MHD to notify the application
800 * that we now expect a response. The application can either 800 * that we now expect a response. The application can either
801 * call #MHD_response_queue() or suspend the request or return 801 * call #MHD_response_queue() or suspend the request and return
802 * #MHD_NO. 802 * NULL to resume processing later, or return NULL without suspending
803 * to close the connection (hard error).
803 * 804 *
804 * @param cls client-defined closure 805 * @param cls client-defined closure
805 * @ingroup request 806 * @ingroup request
806 * @return #MHD_YES if the upload was handled successfully, 807 * @return response object to return, NULL if processing was
807 * #MHD_NO if the socket must be closed due to a serios 808 * suspended or on hard errors; the response object
808 * error while handling the request 809 * will be "consumed" at this point (i.e. the RC decremented)
809 */ 810 */
810typedef enum MHD_Bool 811typedef struct MHD_Response *
811(*MHD_RequestFetchResponseCallback) (void *cls); 812(*MHD_RequestFetchResponseCallback) (void *cls);
812 813
813 814
@@ -1157,21 +1158,103 @@ MHD_request_lookup_value (struct MHD_Request *request,
1157 const char *key); 1158 const char *key);
1158 1159
1159 1160
1161
1160/** 1162/**
1161 * Queue a response to be transmitted to the client (as soon as 1163 * @defgroup httpcode HTTP response codes.
1162 * possible but after the current callback returns). 1164 * These are the status codes defined for HTTP responses.
1163 * 1165 * @{
1164 * @param request the request identifying the client 1166 */
1165 * @param status_code HTTP status code (i.e. #MHD_HTTP_OK) 1167/* See http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml */
1166 * @param response response to transmit 1168enum MHD_HTTP_StatusCode {
1167 * @return #MHD_NO on error (i.e. reply already sent), 1169 MHD_HTTP_CONTINUE = 100,
1168 * #MHD_YES on success or if message has been queued 1170 MHD_HTTP_SWITCHING_PROTOCOLS = 101,
1169 * @ingroup response 1171 MHD_HTTP_PROCESSING = 102,
1170 */ 1172
1171_MHD_EXTERN int 1173 MHD_HTTP_OK = 200,
1172MHD_request_queue_response (struct MHD_Request *request, 1174 MHD_HTTP_CREATED = 201,
1173 unsigned int status_code, 1175 MHD_HTTP_ACCEPTED = 202,
1174 struct MHD_Response *response); 1176 MHD_HTTP_NON_AUTHORITATIVE_INFORMATION = 203,
1177 MHD_HTTP_NO_CONTENT = 204,
1178 MHD_HTTP_RESET_CONTENT = 205,
1179 MHD_HTTP_PARTIAL_CONTENT = 206,
1180 MHD_HTTP_MULTI_STATUS = 207,
1181 MHD_HTTP_ALREADY_REPORTED = 208,
1182
1183 MHD_HTTP_IM_USED = 226,
1184
1185 MHD_HTTP_MULTIPLE_CHOICES = 300,
1186 MHD_HTTP_MOVED_PERMANENTLY = 301,
1187 MHD_HTTP_FOUND = 302,
1188 MHD_HTTP_SEE_OTHER = 303,
1189 MHD_HTTP_NOT_MODIFIED = 304,
1190 MHD_HTTP_USE_PROXY = 305,
1191 MHD_HTTP_SWITCH_PROXY = 306,
1192 MHD_HTTP_TEMPORARY_REDIRECT = 307,
1193 MHD_HTTP_PERMANENT_REDIRECT = 308,
1194
1195 MHD_HTTP_BAD_REQUEST = 400,
1196 MHD_HTTP_UNAUTHORIZED = 401,
1197 MHD_HTTP_PAYMENT_REQUIRED = 402,
1198 MHD_HTTP_FORBIDDEN = 403,
1199 MHD_HTTP_NOT_FOUND = 404,
1200 MHD_HTTP_METHOD_NOT_ALLOWED = 405,
1201 MHD_HTTP_NOT_ACCEPTABLE = 406,
1202/** @deprecated */
1203#define MHD_HTTP_METHOD_NOT_ACCEPTABLE \
1204 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_METHOD_NOT_ACCEPTABLE is deprecated, use MHD_HTTP_NOT_ACCEPTABLE") MHD_HTTP_NOT_ACCEPTABLE
1205 MHD_HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
1206 MHD_HTTP_REQUEST_TIMEOUT = 408,
1207 MHD_HTTP_CONFLICT = 409,
1208 MHD_HTTP_GONE = 410,
1209 MHD_HTTP_LENGTH_REQUIRED = 411,
1210 MHD_HTTP_PRECONDITION_FAILED = 412,
1211 MHD_HTTP_PAYLOAD_TOO_LARGE = 413,
1212/** @deprecated */
1213#define MHD_HTTP_REQUEST_ENTITY_TOO_LARGE \
1214 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_REQUEST_ENTITY_TOO_LARGE is deprecated, use MHD_HTTP_PAYLOAD_TOO_LARGE") MHD_HTTP_PAYLOAD_TOO_LARGE
1215 MHD_HTTP_URI_TOO_LONG = 414,
1216/** @deprecated */
1217#define MHD_HTTP_REQUEST_URI_TOO_LONG \
1218 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_REQUEST_URI_TOO_LONG is deprecated, use MHD_HTTP_URI_TOO_LONG") MHD_HTTP_URI_TOO_LONG
1219 MHD_HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
1220 MHD_HTTP_RANGE_NOT_SATISFIABLE = 416,
1221/** @deprecated */
1222#define MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE \
1223 _MHD_DEPR_IN_MACRO("Value MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE is deprecated, use MHD_HTTP_RANGE_NOT_SATISFIABLE") MHD_HTTP_RANGE_NOT_SATISFIABLE
1224 MHD_HTTP_EXPECTATION_FAILED = 417,
1225
1226 MHD_HTTP_MISDIRECTED_REQUEST = 421,
1227 MHD_HTTP_UNPROCESSABLE_ENTITY = 422,
1228 MHD_HTTP_LOCKED = 423,
1229 MHD_HTTP_FAILED_DEPENDENCY = 424,
1230 MHD_HTTP_UNORDERED_COLLECTION = 425,
1231 MHD_HTTP_UPGRADE_REQUIRED = 426,
1232
1233 MHD_HTTP_PRECONDITION_REQUIRED = 428,
1234 MHD_HTTP_TOO_MANY_REQUESTS = 429,
1235 MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
1236
1237 MHD_HTTP_NO_RESPONSE = 444,
1238
1239 MHD_HTTP_RETRY_WITH = 449,
1240 MHD_HTTP_BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS = 450,
1241 MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
1242
1243 MHD_HTTP_INTERNAL_SERVER_ERROR = 500,
1244 MHD_HTTP_NOT_IMPLEMENTED = 501,
1245 MHD_HTTP_BAD_GATEWAY = 502,
1246 MHD_HTTP_SERVICE_UNAVAILABLE = 503,
1247 MHD_HTTP_GATEWAY_TIMEOUT = 504,
1248 MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED = 505,
1249 MHD_HTTP_VARIANT_ALSO_NEGOTIATES = 506,
1250 MHD_HTTP_INSUFFICIENT_STORAGE = 507,
1251 MHD_HTTP_LOOP_DETECTED = 508,
1252 MHD_HTTP_BANDWIDTH_LIMIT_EXCEEDED = 509,
1253 MHD_HTTP_NOT_EXTENDED = 510,
1254 MHD_HTTP_NETWORK_AUTHENTICATION_REQUIRED 511
1255
1256};
1257/** @} */ /* end of group httpcode */
1175 1258
1176 1259
1177/** 1260/**
@@ -1262,6 +1345,7 @@ MHD_response_set_options (struct MHD_Response *response,
1262 * Create a response object. The response object can be extended with 1345 * Create a response object. The response object can be extended with
1263 * header information and then be used any number of times. 1346 * header information and then be used any number of times.
1264 * 1347 *
1348 * @param sc status code to return
1265 * @param size size of the data portion of the response, #MHD_SIZE_UNKNOWN for unknown 1349 * @param size size of the data portion of the response, #MHD_SIZE_UNKNOWN for unknown
1266 * @param block_size preferred block size for querying crc (advisory only, 1350 * @param block_size preferred block size for querying crc (advisory only,
1267 * MHD may still call @a crc using smaller chunks); this 1351 * MHD may still call @a crc using smaller chunks); this
@@ -1275,7 +1359,8 @@ MHD_response_set_options (struct MHD_Response *response,
1275 * @ingroup response 1359 * @ingroup response
1276 */ 1360 */
1277_MHD_EXTERN struct MHD_Response * 1361_MHD_EXTERN struct MHD_Response *
1278MHD_response_from_callback (uint64_t size, 1362MHD_response_from_callback (enum MHD_HTTP_StatusCode sc,
1363 uint64_t size,
1279 size_t block_size, 1364 size_t block_size,
1280 MHD_ContentReaderCallback crc, 1365 MHD_ContentReaderCallback crc,
1281 void *crc_cls, 1366 void *crc_cls,
@@ -1322,6 +1407,8 @@ enum MHD_ResponseMemoryMode
1322 * Create a response object. The response object can be extended with 1407 * Create a response object. The response object can be extended with
1323 * header information and then be used any number of times. 1408 * header information and then be used any number of times.
1324 * 1409 *
1410 * @param sc status code to use for the response;
1411 * #MHD_HTTP_NO_CONTENT is only valid if @a size is 0;
1325 * @param size size of the data portion of the response 1412 * @param size size of the data portion of the response
1326 * @param buffer size bytes containing the response's data portion 1413 * @param buffer size bytes containing the response's data portion
1327 * @param mode flags for buffer management 1414 * @param mode flags for buffer management
@@ -1329,7 +1416,8 @@ enum MHD_ResponseMemoryMode
1329 * @ingroup response 1416 * @ingroup response
1330 */ 1417 */
1331_MHD_EXTERN struct MHD_Response * 1418_MHD_EXTERN struct MHD_Response *
1332MHD_response_from_buffer (size_t size, 1419MHD_response_from_buffer (enum MHD_HTTP_StatusCode sc,
1420 size_t size,
1333 void *buffer, 1421 void *buffer,
1334 enum MHD_ResponseMemoryMode mode); 1422 enum MHD_ResponseMemoryMode mode);
1335 1423
@@ -1339,6 +1427,7 @@ MHD_response_from_buffer (size_t size,
1339 * data is read. The response object can be extended with 1427 * data is read. The response object can be extended with
1340 * header information and then be used any number of times. 1428 * header information and then be used any number of times.
1341 * 1429 *
1430 * @param sc status code to return
1342 * @param fd file descriptor referring to a file on disk with the 1431 * @param fd file descriptor referring to a file on disk with the
1343 * data; will be closed when response is destroyed; 1432 * data; will be closed when response is destroyed;
1344 * fd should be in 'blocking' mode 1433 * fd should be in 'blocking' mode
@@ -1352,7 +1441,8 @@ MHD_response_from_buffer (size_t size,
1352 * @ingroup response 1441 * @ingroup response
1353 */ 1442 */
1354_MHD_EXTERN struct MHD_Response * 1443_MHD_EXTERN struct MHD_Response *
1355MHD_response_from_fd (int fd, 1444MHD_response_from_fd (enum MHD_HTTP_StatusCode sc,
1445 int fd,
1356 uint64_t offset, 1446 uint64_t offset,
1357 uint64_t size); 1447 uint64_t size);
1358 1448
@@ -1423,7 +1513,7 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh,
1423 * of this function should never block (as it will still be called 1513 * of this function should never block (as it will still be called
1424 * from within the main event loop). 1514 * from within the main event loop).
1425 * 1515 *
1426 * @param cls closure, whatever was given to #MHD_create_response_for_upgrade(). 1516 * @param cls closure, whatever was given to #MHD_response_create_for_upgrade().
1427 * @param connection original HTTP connection handle, 1517 * @param connection original HTTP connection handle,
1428 * giving the function a last chance 1518 * giving the function a last chance
1429 * to inspect the original HTTP request 1519 * to inspect the original HTTP request
@@ -1470,8 +1560,9 @@ typedef void
1470 * to the OS; if there are communication errors before, the usual MHD 1560 * to the OS; if there are communication errors before, the usual MHD
1471 * connection error handling code will be performed. 1561 * connection error handling code will be performed.
1472 * 1562 *
1473 * Setting the correct HTTP code (i.e. MHD_HTTP_SWITCHING_PROTOCOLS) 1563 * MHD will automatically set the correct HTTP status
1474 * and setting correct HTTP headers for the upgrade must be done 1564 * code (#MHD_HTTP_SWITCHING_PROTOCOLS).
1565 * Setting correct HTTP headers for the upgrade must be done
1475 * manually (this way, it is possible to implement most existing 1566 * manually (this way, it is possible to implement most existing
1476 * WebSocket versions using this API; in fact, this API might be useful 1567 * WebSocket versions using this API; in fact, this API might be useful
1477 * for any protocol switch, not just WebSockets). Note that 1568 * for any protocol switch, not just WebSockets). Note that
@@ -1494,16 +1585,25 @@ MHD_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
1494 1585
1495 1586
1496/** 1587/**
1497 * Destroy a response object and associated resources. Note that 1588 * Decrease reference counter of a response object. If the counter
1498 * libmicrohttpd may keep some of the resources around if the response 1589 * hits zero, destroys a response object and associated resources.
1499 * is still in the queue for some clients, so the memory may not 1590 *
1500 * necessarily be freed immediatley. 1591 * @param response response to decrement RC of
1592 * @ingroup response
1593 */
1594_MHD_EXTERN void
1595MHD_response_decref (struct MHD_Response *response);
1596
1597
1598/**
1599 * Increases reference counter of a response object. Used so that
1600 * the same response object can be queued repeatedly.
1501 * 1601 *
1502 * @param response response to destroy 1602 * @param response response to increment RC for
1503 * @ingroup response 1603 * @ingroup response
1504 */ 1604 */
1505_MHD_EXTERN void 1605_MHD_EXTERN void
1506MHD_response_destroy (struct MHD_Response *response); 1606MHD_response_incref (struct MHD_Response *response);
1507 1607
1508 1608
1509/** 1609/**