Home

Awesome

lua-url

test codecov

url string utility.

Installation

luarocks install url

Encoding

str = encode_uri( str )
str = encode_form( str )
str = encode2396( str )
str = encode3986( str )

encode a string to a percent-encoded string.

Parameters

Returns

Decoding

str, err = decode_uri( str )
str, err = decode_form( str )
str, err = decode( str )

decode a percent-encoded string.

Parameters

Returns

Parser

res, cur, err = parse( url [, parse_query [, init [, is_querystring]]] )

returns the table of parsed url.

Parameters

Returns

Example

local dump = require('dump')
local url = require('url')

local res, cur, err = url.parse(
                          'head http://user:pass@host.com:8080/p/a/t/h/?query=string&query=value#hash tail',
                          true, 5)
print(dump({
    res = res,
    cur = cur,
    err = err,
}))
--[[
{
    cur = 74,
    err = " ",
    res = {
        fragment = "hash",
        host = "host.com:8080",
        hostname = "host.com",
        password = "pass",
        path = "/p/a/t/h/",
        port = "8080",
        query = "?query=string&query=value",
        query_params = {
            query = {
                [1] = "string",
                [2] = "value"
            }
        },
        scheme = "http",
        user = "user",
        userinfo = "user:pass"
    }
}
--]]

res, cur, err = url.parse(
                    'head http://user:pass@host.com:8080/p/a/t/h/?query=string&query=value#hash tail',
                    false, 5)
print(dump({
    res = res,
    cur = cur,
    err = err,
}))
--[[
{
    cur = 74,
    err = " ",
    res = {
        fragment = "hash",
        host = "host.com:8080",
        hostname = "host.com",
        password = "pass",
        path = "/p/a/t/h/",
        port = "8080",
        query = "?query=string&query=value",
        scheme = "http",
        user = "user",
        userinfo = "user:pass"
    }
}
--]]

-- parse query
res, cur, err = url.parse('head query=string&query=value#hash tail', true, 5,
                          true)
print(dump({
    res = res,
    cur = cur,
    err = err,
}))
--[[
{
    cur = 34,
    err = " ",
    res = {
        fragment = "hash",
        query = "query=string&query=value",
        query_params = {
            query = {
                [1] = "string",
                [2] = "value"
            }
        }
    }
}
--]]