-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
refactor: support percent-encoded /unix paths #10833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,9 @@ import ( | |||||||
| "net" | ||||||||
| "net/http" | ||||||||
| _ "net/http/pprof" | ||||||||
| "net/url" | ||||||||
| "os" | ||||||||
| "path/filepath" | ||||||||
| "regexp" | ||||||||
| "runtime" | ||||||||
| "sort" | ||||||||
|
|
@@ -704,6 +706,24 @@ take effect. | |||||||
| return errs | ||||||||
| } | ||||||||
|
|
||||||||
| // TODO: should a version of this live in https://github.com/multiformats/go-multiaddr | ||||||||
| // so we dont need to duplicate code here and in client/rpc/api.go ? | ||||||||
| func NormalizeUnixMultiaddr(address string) string { | ||||||||
| // Support legacy and modern /unix addrs | ||||||||
| // https://github.com/multiformats/multiaddr/pull/174 | ||||||||
| socketPath, err := url.PathUnescape(address) | ||||||||
| if err != nil { | ||||||||
| return address // nil, fmt.Errorf("failed to unescape /unix socket path: %w", err) | ||||||||
| } | ||||||||
| // Ensure the path is absolute | ||||||||
| if !strings.HasPrefix(socketPath, string(filepath.Separator)) { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| socketPath = string(filepath.Separator) + socketPath | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it correct to prepend a separator, or should the current directory be prepended? See |
||||||||
| } | ||||||||
| // Normalize path | ||||||||
| socketPath = filepath.Clean(socketPath) | ||||||||
| return socketPath | ||||||||
|
Comment on lines
+723
to
+724
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } | ||||||||
|
|
||||||||
|
Comment on lines
+709
to
+726
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IF It does not live in https://github.com/multiformats/go-multiaddr then multiformats/multiaddr#174 is effectively a dead spec IMO, because nobody will use percent-encoded version.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. If we are going to support multiformats/multiaddr#174 then this should live in |
||||||||
| // serveHTTPApi collects options, creates listener, prints status message and starts serving requests. | ||||||||
| func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error) { | ||||||||
| cfg, err := cctx.GetConfig() | ||||||||
|
|
@@ -730,6 +750,9 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error | |||||||
| } | ||||||||
|
|
||||||||
| for _, addr := range apiAddrs { | ||||||||
| if strings.HasPrefix(addr, "/unix/") { | ||||||||
| addr = NormalizeUnixMultiaddr(addr) | ||||||||
| } | ||||||||
| apiMaddr, err := ma.NewMultiaddr(addr) | ||||||||
| if err != nil { | ||||||||
| return nil, fmt.Errorf("serveHTTPApi: invalid API address: %q (err: %s)", addr, err) | ||||||||
|
|
@@ -919,6 +942,9 @@ func serveHTTPGateway(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, e | |||||||
|
|
||||||||
| gatewayAddrs := cfg.Addresses.Gateway | ||||||||
| for _, addr := range gatewayAddrs { | ||||||||
| if strings.HasPrefix(addr, "/unix/") { | ||||||||
| addr = NormalizeUnixMultiaddr(addr) | ||||||||
| } | ||||||||
| gatewayMaddr, err := ma.NewMultiaddr(addr) | ||||||||
| if err != nil { | ||||||||
| return nil, fmt.Errorf("serveHTTPGateway: invalid gateway address: %q (err: %s)", addr, err) | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N.b. in the latest version of the spec pr, relative paths are supported