在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):golgote/neturl开源软件地址(OpenSource Url):https://github.com/golgote/neturl开源编程语言(OpenSource Language):Lua 100.0%开源软件介绍(OpenSource Introduction):A Robust URL Parser and Builder for LuaThis small Lua library provides a few functions to parse URL with querystring and build new URL easily. url = require "net.url" URL parserThe library converts an URL to a table of the elements as described in RFC : scheme, host, path, etc. u = url.parse("http://www.example.com/test/?start=10")
print(u.scheme)
-- http
print(u.host)
-- www.example.com
print(u.path)
-- /test/ URL normalizationu = url.parse("http://www.FOO.com:80///foo/../foo/./bar"):normalize()
print(u)
-- http://www.foo.com/foo/bar URL resolverURL resolution follows the examples provided in the RFC 2396. u = url.parse("http://a/b/c/d;p?q"):resolve("../../g")
print(u)
-- http://a/g Path builderPath segments can be added using the u = url.parse('http://example.com')
u / 'bands' / 'AC/DC'
print(u)
-- http://example.com/bands/AC%2FDC Module Options
If one wants to have the url = require "net.url"
url.options.legal_in_path["+"] = true; Querystring parserThe library supports brackets in querystrings, like PHP. It means you can use brackets to build multi-dimensional tables. The parsed querystring has a tostring() helper. As usual with Lua, if no index is specified, it starts from index 1. query = url.parseQuery("first=abc&a[]=123&a[]=false&b[]=str&c[]=3.5&a[]=last")
print(query)
-- a[1]=123&a[2]=false&a[3]=last&b[1]=str&c[1]=3.5&first=abc
print(query.a[1])
-- 123 Querystring builderu = url.parse("http://www.example.com")
u.query.foo = "bar"
print(u)
-- http://www.example.com/?foo=bar
u:setQuery{ json = true, skip = 100 }
print(u)
-- http://www.example.com/?json=true&skip=100 Differences with luasocket/url.lua
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论