diff --git a/docs/howto/hooks/lua.md b/docs/howto/hooks/lua.md index 1f73de8a775..79abbab7704 100644 --- a/docs/howto/hooks/lua.md +++ b/docs/howto/hooks/lua.md @@ -420,6 +420,25 @@ The `value` string should be in [ISO8601](https://en.wikipedia.org/wiki/ISO_8601 Returns a new 128-bit [RFC 4122 UUID](https://www.rfc-editor.org/rfc/rfc4122){: target="_blank" } in string representation. +### `net/url` + +Provides a `parse` function that parses a raw url into a URL structure. +The url may be relative (a path, without a host) or absolute (starting with a scheme). Trying to parse a hostname and path without a scheme is invalid but may not necessarily return an error, due to parsing ambiguities. + + +```lua +> local url = require("net/url") +> url.parse("https://example.com/path?p1=a#section") +{ + ["host"] = "example.com" + ["path"] = "/path" + ["scheme"] = "https" + ["query"] = "p1=a" + ["fragment"] = "section" +} +``` + + ### `net/http` (optional) Provides a `request` function that performs an HTTP request. diff --git a/pkg/actions/lua/net/url/url.go b/pkg/actions/lua/net/url/url.go index f287b164554..ad8c4612fbd 100644 --- a/pkg/actions/lua/net/url/url.go +++ b/pkg/actions/lua/net/url/url.go @@ -28,9 +28,10 @@ func parse(l *lua.State) int { panic("unreachable") } return util.DeepPush(l, map[string]string{ - "host": u.Host, - "path": u.Path, - "scheme": u.Scheme, - "query": u.RawQuery, + "host": u.Host, + "path": u.Path, + "scheme": u.Scheme, + "query": u.RawQuery, + "fragment": u.Fragment, }) } diff --git a/pkg/actions/lua/open.go b/pkg/actions/lua/open.go index 2a40bd4ec1d..a573941209e 100644 --- a/pkg/actions/lua/open.go +++ b/pkg/actions/lua/open.go @@ -13,6 +13,7 @@ import ( "github.com/treeverse/lakefs/pkg/actions/lua/encoding/parquet" "github.com/treeverse/lakefs/pkg/actions/lua/encoding/yaml" "github.com/treeverse/lakefs/pkg/actions/lua/net/http" + "github.com/treeverse/lakefs/pkg/actions/lua/net/url" "github.com/treeverse/lakefs/pkg/actions/lua/path" "github.com/treeverse/lakefs/pkg/actions/lua/regexp" "github.com/treeverse/lakefs/pkg/actions/lua/storage/aws" @@ -41,6 +42,7 @@ func Open(l *lua.State, ctx context.Context, cfg OpenSafeConfig) { path.Open(l) aws.Open(l, ctx) gcloud.Open(l, ctx) + url.Open(l) if cfg.NetHTTPEnabled { http.Open(l) }