Skip to content
Snippets Groups Projects
Commit 37c35677 authored by mechanik20051988's avatar mechanik20051988 Committed by Kirill Yukhin
Browse files

uri: implement ability to parse URIs passed in different ways

Previously, URI can be passed as a string, which contains one URI
or several URIs separated by commas. Now URIs can be passed in
different ways: as before, as a table which contains URI and it's
parameters in "param" table, as a table which contains URI strings
and URI tables. Also there are different ways to specify properties
for URI: in a string which contains URI, after '?' delimiter, in a
table which contains URI in "params" table, in "default_params" table
if it is default parameters for all URIs.
For this purposes new method `parse_many` was implemented in tarantool
`uri` library. Also `parse` method was updated to make possible the
same as new `parse_many` method but only for single URI.
```lua
uri = require('uri')
-- Single URI, passed as before
uri.parse_many("/tmp/unix.sock")
-- Single URI, with query paramters
uri.parse_many("/tmp/unix.sock?q1=v1&q2=v2")
-- Several URIs with parameters in one string, separated by commas
uri.parse_many("/tmp/unix.sock_1?q=v, /tmp/unix.sock_2?q=v")
-- Single URI passed in table, with additional parameters, passed
-- in "params" table. This parameters overwrite parameters from
-- URI string (q1 = "v2" in example below).
uri.parse_many({"/tmp/unix.sock?q1=v1", params = {q1 = "v2"}})
-- For parse it's also works now
uri.parse({"/tmp/unix.sock?q1=v1", params = {q1 = "v2"}})
-- Several URIs passed in table with default parameters, passed
-- in "default_params" table, which are used for parameters, which
-- not specified for URI (q3 parameter with "v3" value corresponds
-- to all URIs, and used if there is no such parameter in URI).
uri.parse_many({
    "/tmp/unix.sock_1?q1=v1",
    { uri = "/tmp/unix.sock_2", params = { q2 = "v2" } },
    default_params = { q3 = "v3" }
})
```
parent 3661bc3a
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment