Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
httpc: introduce format_query and parse_query functions
Previous patch introduced url_escape and url_unescape. However it's quite poorly to give our users too low-level functions. The main use case is to form and parse http query parameters This patch introduces format_query and parse_query functions Closes #3682 @TarantoolBot document Title: New http.client functions Four new functions are available in http.client module: - url_escape - simple wrapper over curl_easy_escape (https://curl.haxx.se/libcurl/c/curl_easy_escape.html) - url_unescape - simple wrapper over curl_easy_unescape (https://curl.haxx.se/libcurl/c/curl_easy_unescape.html) Examples: ```lua -- According RFC3986 tarantool> httpc.url_escape('hello') --- - hello ... tarantool> httpc.url_escape('Привет') --- - '%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82' ... tarantool> httpc.url_escape('$&+,:;=?@-._~') --- - '%24%26%2B%2C%3A%3B%3D%3F%40-._~' ... ``` - format_query - format query arguments from key-value string pairs for HTTP request - parse_query - parse query string into table Example: ```lua -- The query string is composed of a series of field-value pairs -- Within each pair, the field name and value are -- separated by an equals sign, "=" -- The series of pairs is separated by the ampersand, "&" tarantool> httpc.format_query({['hello'] = 'world', ['привет'] = 'мир'}) --- - '%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82=%D0%BC%D0%B8%D1%80&hello=world' ... tarantool> httpc.parse_query('%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82=' .. '%D0%BC%D0%B8%D1%80&hello=world') --- - привет: мир hello: world ... ```
- Loading branch information