owncloud / owncloud/ocis

ocdav makes download requests using the proxy, not the datagateway directly

Open
#6,296 1 comment 1 reaction 0 assignees View on GitHub
Type:Bug
Dominant language
Go
Stars
2.1k
Forks
274
Avg merge
2d 1h
Merged PRs (30d)
103

Description

The ocdav service currently sends PUT and TUS requests for uploads to the proxy again instead of directly going to the dataprovider ... or datagateway.

![image](https://github.com/owncloud/ocis/assets/956847/21e7c909-8f12-4008-89de-9139584c4273)

While this does not look too bad for small files, we are paying a latency cost for two extra network hops as well as having to copy the byte stream twice.

We could send it to a datagateway, which in ocis runs as part of the frontend, so it would be sth like:
```diff
+ // FIXME the gateway returns the frontend URL ... but we don't want to go through the proxy again ...
+ // the jwt token contains the actual target, go there directly
+ reg := registry.GetRegistry()
+ sel := selector.NewSelector(selector.Registry(reg))
+ // select next datagateway node
+ next, err := sel.Select("com.owncloud.web.frontend")
+ if err != nil {
+ log.Error().Err(err).Msg("error selecting datagateway service")
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+ node, err := next()
+ if err != nil {
+ log.Error().Err(err).Msg("error selecting next node")
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ epURL, err := url.Parse(ep)
+ if err != nil {
+ log.Error().Err(err).Msg("could not parse endpoint")
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ // replace frontend endpoint with internal address
+ epURL.Host = node.Address
+ // we may need a protocol switch
+ if node.Metadata["protocol"] != "" {
+ epURL.Scheme = node.Metadata["protocol"]
+ }
+ epURL.Path = "/data" // overwrite path, we know the datagateway uses the /data endpoint
+ ep = epURL.String()
+
httpReq, err := rhttp.NewRequest(ctx, http.MethodPut, ep, r.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
+ Propagator.Inject(ctx, propagation.HeaderCarrier(httpReq.Header))
httpReq.Header.Set(datagateway.TokenTransportHeader, token)

httpRes, err := s.client.Do(httpReq)
```

but this requires importing the ocis registry into reva ...

It should just send the request directly to the correct dataprovider ...

- we could unpack the token, but it requires parsing the JWT transfertoken ... for that we would have to know the transfertokensecret
- we could return an internal endpoint? but we don't really want to expose that ...

I prefer making parsing the transfer token optional. If it is set the ocdav service should parse it and directly talk to the correct dataprovider, skipping the proxy and the datagateway.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.