You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-7Lines changed: 19 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -278,19 +278,30 @@ Send the HTTP request, including the specified content. If a file transfer was s
278
278
279
279
Once a complete response has been received from the server, the response function is called with the provided origin value, the HTTP status from the server and the data content from the response, if any. The attributes from the response header can be accessed using the standard echttp API.
280
280
281
-
The echttp client functions do not automatically follow redirection (HTTP status 302): the application must do this itself if this is the intent. For example:
281
+
The echttp client functions do not automatically follow redirection (HTTP status 301, 302, 303, 307 or 308): the application must do this itself if this is the intent. The echttp API provide a helper function to make it easier:
282
+
```
283
+
int echttp_redirected (const char *method);
284
+
```
285
+
This function handles the common cases of redirections. If used, this must be called from the application's response callback, and it must be the first thing that the response callback do. How the response callback then behaves depends on the return code:
286
+
* Non-zero: the response was not handled and the response must be processed as normal. The value returned is an updated HTTP status.
287
+
* 0: the response was fully handled and the response callback must now (re)build the request data, call echttp_submit and then return without processing the response further.
288
+
289
+
The method parameter is the method used for the original request. Depending on the redirect code, either this method will be used or else the GET method will be forced.
290
+
291
+
It is always possible for the application to handle redirections on its own, if the case is too complex for this helper. Do not forget, however, to handle all the redirection codes (301, 302, 303, 207 and 308).
292
+
293
+
For example:
282
294
```
283
295
static void response (void *origin, int status, char *data, int length) {
The echttp library provides functions to handle JSON and XML data: a small JSON parser, a small XML parser and a JSON generator. These are built using the same approach as echttp itself: make the API simple to use. This parser support is a separate extension and requires to include echttp_json.h or echttp_xml.h (depending on the format used).
@@ -343,7 +354,8 @@ This token structure closely matches the JSON syntax. When decoding XML, the fol
343
354
344
355
```
345
356
char *echttp_parser_load (const char *file);
346
-
void echttp_parser_free (char *buffer);
357
+
char *echttp_parser_string (const char *text);
358
+
void echttp_parser_free (char *buffer);
347
359
```
348
360
These functions are used to load the entire content of a JSON or XML file in a buffer, before parsing the data. The buffer is dynamically allocated, and must be released once the data is no longer used. Because the parsed tokens rely on the buffer's content, the buffer should be released only after the tokens have been discarded.
0 commit comments