Skip to content

Commit 102d705

Browse files
committed
Partially reverted logic to access a remote share, see PR comments
1 parent cfb4f3f commit 102d705

File tree

1 file changed

+13
-5
lines changed
  • internal/http/services/opencloudmesh/ocmd

1 file changed

+13
-5
lines changed

internal/http/services/opencloudmesh/ocmd/shares.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -264,19 +264,27 @@ func getAndResolveProtocols(p Protocols, r *http.Request) ([]*ocm.Protocol, erro
264264
uri = ocmProto.GetWebappOptions().Uri
265265
}
266266

267-
// Irrespective from the presence of a full `uri` in the payload (deprecated), validate the
268-
// remote is an OCM server and resolve the remote root
269-
// yet skip this if the remote is localhost (for integration tests)
270-
if strings.Contains(uri, "localhost") {
267+
// If the `uri` contains a hostname, use it as is
268+
u, _ := url.Parse(uri)
269+
if u.Host != "" {
271270
protos = append(protos, ocmProto)
272271
continue
273272
}
273+
// otherwise resolve the hostname using the OCM discovery endpoint
274274
remoteRoot, err := discoverOcmRoot(r, protocolName)
275275
if err != nil {
276276
return nil, err
277277
}
278+
if strings.HasPrefix(uri, "/") {
279+
// only take the host from remoteRoot and append the absolute uri
280+
u, _ := url.Parse(remoteRoot)
281+
u.Path = uri
282+
uri = u.String()
283+
} else {
284+
// relative uri
285+
uri, _ = url.JoinPath(remoteRoot, uri)
286+
}
278287

279-
uri, _ = url.JoinPath(remoteRoot, uri[strings.LastIndex(uri, "/")+1:])
280288
switch protocolName {
281289
case "webdav":
282290
ocmProto.GetWebdavOptions().Uri = uri

0 commit comments

Comments
 (0)