diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-01-19 20:13:23 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-01-19 20:13:23 +0100 |
commit | 639435c2158e95b2eca5d0f77d2c2fa8ae3d3f5b (patch) | |
tree | e59706fb89faea60541c1440582772df6b5dee0f | |
parent | bcfdf016a44168d3ccaffc05e63f2c0030eb9988 (diff) | |
download | libmicrohttpd-639435c2158e95b2eca5d0f77d2c2fa8ae3d3f5b.tar.gz libmicrohttpd-639435c2158e95b2eca5d0f77d2c2fa8ae3d3f5b.zip |
notes on MHD2 API
-rw-r--r-- | src/include/microhttpd2.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h index 4a4541fa..21bdee29 100644 --- a/src/include/microhttpd2.h +++ b/src/include/microhttpd2.h | |||
@@ -66,6 +66,96 @@ | |||
66 | * - simplify API for common-case of one-shot responses by | 66 | * - simplify API for common-case of one-shot responses by |
67 | * eliminating need for destroy response in most cases; | 67 | * eliminating need for destroy response in most cases; |
68 | * | 68 | * |
69 | * NEW-EG: | ||
70 | * - avoid fixed types, like uint32_t. They may not exist on some | ||
71 | * platforms. Instead use uint_fast32_t. | ||
72 | * It is also better for future-proof. | ||
73 | * - check portability for embedded platforms. Some of them support | ||
74 | * 64 bits, but 'int' could be just 16 bits resulting of silently | ||
75 | * dropping enum values higher than 65535. | ||
76 | * => in general, more functions, fewer enums for setup | ||
77 | * | ||
78 | * - Avoid returning pointers to internal members. It is not thread-safe and | ||
79 | * even in single thread the value could change over the time. Prefer pointers to | ||
80 | * app-allocated memory with the size, like MHD_daemon_get_static_info(enum | ||
81 | * MHD_enum_name info_type, void *buf, size_t buf_size). | ||
82 | * => Except in cases where zero-copy matters. | ||
83 | * | ||
84 | * - Use separate app calls/functions for data the will not change for the | ||
85 | * lifetime of the object and dynamic data. The only difference should be the | ||
86 | * name. Like MHD_daemon_get_static_info(enum MHD_enum_name info_type, void *buf, | ||
87 | * size_t buf_size) MHD_daemon_get_dynamic_info(enum MHD_enum_name info_type, | ||
88 | * void *buf, size_t buf_size) Examples of static data: listen socket, number of | ||
89 | * workers, daemon flags. Examples of dynamic data: number of connections, | ||
90 | * quiesce status. It should give a clear idea whether the data could be changed | ||
91 | * over the time (could be not obvious for some data) and thus may change the | ||
92 | * approach how to use the data in app. The same for: library, daemon, | ||
93 | * connection, request. Not sure that dynamic data makes sense for the library. | ||
94 | * | ||
95 | * - Use clear separation between connection and request. Do not mix the kind | ||
96 | * data in the callbacks. Currently we are mixing things in | ||
97 | * MHD_AccessHandlerCallback and MHD_RequestCompletedCallback. Instead of | ||
98 | * pointers to struct MHD_Connection we should use pointers to (new) struct | ||
99 | * MHD_Request. Probably some other functions are mixing the things as well, to | ||
100 | * be re-checked. | ||
101 | * | ||
102 | * - Define default response code in response object. There are a very little | ||
103 | * chance that response body designed for 404 or 403 codes will be used with | ||
104 | * 200 code. However, the responses body for 307 and 308 could be the same. So: | ||
105 | * * add default response code in response object. Use zero for default 200. | ||
106 | * * When app sending the response use zero for response's default code or | ||
107 | * use specific code to override response's default value. | ||
108 | * | ||
109 | * - Make responses unmodifiable after first use. It is not thread-safe. | ||
110 | * MHD-generated headers (Date, Connection/Keep-Alive) are again | ||
111 | * part of the *request* and do not count as part of the "response" here. | ||
112 | * | ||
113 | * - Remove "footers" from responses. With unmodifiable responses everything should be "headers". | ||
114 | * Add footers to *requests* instead. | ||
115 | * | ||
116 | * - Add API for adding request-specific response headers and footers. To | ||
117 | * simplify the things it should just copy the strings (to avoid dealing with | ||
118 | * complicated deinit of possible dynamic strings). After this change it should | ||
119 | * be possible to simplify DAuth handling as response could be reused (currently | ||
120 | * 403 responses are modified for each reply). | ||
121 | * | ||
122 | * - Control response behaviour mainly by response flags, not by additional | ||
123 | * headers (like MHD_RF_FORCE_CLOSE instead of "Connection: close"). | ||
124 | * It is easier for both: app and MHD. | ||
125 | * | ||
126 | * - Move response codes from MHD_HTTP_xxx namespace to MHD_HTTP_CODE_xxx | ||
127 | * namespace. It already may clash with other HTTP values. | ||
128 | * | ||
129 | * - plus other things that was discussed already, like avoiding extra calls | ||
130 | * for body-less requests. I assume it should be resolved with fundamental | ||
131 | * re-design of request/response cycle handling. | ||
132 | * | ||
133 | * - Internals: carefully check where locking is really required. Probably | ||
134 | * separate locks. Check out-of-thread value reading. Currently code assumes | ||
135 | * atomic reading of values used in other threads, which mostly true on x86, | ||
136 | * but not OK on other arches. Probably use read/write locking to minimize | ||
137 | * the threads interference. | ||
138 | * | ||
139 | * - figure out how to do portable variant of cork/uncork | ||
140 | * | ||
141 | * NEW-CG: | ||
142 | * - Postprocessor is unusable night-mare when doing "stream processing" | ||
143 | * for tiny values where the application basically has to copy together | ||
144 | * the stream back into a single compact heap value, just making the | ||
145 | * parsing highly more complicated (see examples in Challenger) | ||
146 | * | ||
147 | * - non-stream processing variant for request bodies, give apps a | ||
148 | * way to request the full body in one buffer; give apps a way | ||
149 | * to request a 'large new allocation' for such buffers; give apps | ||
150 | * a way to specify a global quota for large allocations to ensure | ||
151 | * memory usage has a hard bound | ||
152 | * | ||
153 | * - remove request data from memory pool when response is queued | ||
154 | * (IF no callbacks and thus data cannot be used anymore, or IF | ||
155 | * application permits explictly per daemon) to get more space | ||
156 | * for building response; | ||
157 | * | ||
158 | * | ||
69 | * TODO: | 159 | * TODO: |
70 | * - varargs in upgrade is still there and ugly (and not even used!) | 160 | * - varargs in upgrade is still there and ugly (and not even used!) |
71 | * - migrate event loop apis (get fdset, timeout, MHD_run(), etc.) | 161 | * - migrate event loop apis (get fdset, timeout, MHD_run(), etc.) |