Skip to content

Commit

Permalink
Fallback to Upload-Length header
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Aug 18, 2020
1 parent cd67847 commit 97381a2
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
3 changes: 0 additions & 3 deletions examples/storage-references/gateway.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
commit_share_to_storage_grant = true
commit_share_to_storage_ref = true

[grpc.services.gateway.token_managers.jwt]
expires = 86400

[grpc.services.storageregistry]
[grpc.services.storageregistry.drivers.static]
home_provider = "/home"
Expand Down
4 changes: 2 additions & 2 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi
ep, opaque, err := s.webdavRefTransferEndpoint(ctx, statRes.Info.Target, shareChild)
if err != nil {
return &gateway.InitiateFileDownloadResponse{
Status: status.NewInternal(ctx, err, "gateway: error creating container on webdav host: "+p),
Status: status.NewInternal(ctx, err, "gateway: error downloading from webdav host: "+p),
}, nil
}
return &gateway.InitiateFileDownloadResponse{
Expand Down Expand Up @@ -343,7 +343,7 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile
ep, opaque, err := s.webdavRefTransferEndpoint(ctx, statRes.Info.Target, shareChild)
if err != nil {
return &gateway.InitiateFileUploadResponse{
Status: status.NewInternal(ctx, err, "gateway: error resolving webdav host: "+p),
Status: status.NewInternal(ctx, err, "gateway: error uploading to webdav host: "+p),
}, nil
}
return &gateway.InitiateFileUploadResponse{
Expand Down
11 changes: 6 additions & 5 deletions internal/grpc/services/gateway/webdavstorageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package gateway

import (
"context"
"fmt"
"net/url"
"path"
"strings"
Expand Down Expand Up @@ -55,7 +56,7 @@ func (s *svc) webdavRefStat(ctx context.Context, targetURL string, nameQueries .
// ownloud-specific fields to get the resource ID and permissions.
info, err := c.Stat(ep.filePath)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling stat at the webdav endpoint: "+ep.endpoint)
return nil, errors.Wrap(err, fmt.Sprintf("gateway: error statting %s at the webdav endpoint: %s", ep.filePath, ep.endpoint))
}
return normalize(info.(*gowebdav.File)), nil
}
Expand All @@ -77,7 +78,7 @@ func (s *svc) webdavRefLs(ctx context.Context, targetURL string, nameQueries ...
// ownloud-specific fields to get the resource ID and permissions.
infos, err := c.ReadDir(ep.filePath)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling stat at the webdav endpoint: "+ep.endpoint)
return nil, errors.Wrap(err, fmt.Sprintf("gateway: error listing %s at the webdav endpoint: %s", ep.filePath, ep.endpoint))
}

mds := []*provider.ResourceInfo{}
Expand All @@ -103,7 +104,7 @@ func (s *svc) webdavRefMkdir(ctx context.Context, targetURL string, nameQueries

err = c.Mkdir(ep.filePath, 0700)
if err != nil {
return errors.Wrap(err, "gateway: error calling mkdir at the webdav endpoint: "+ep.endpoint)
return errors.Wrap(err, fmt.Sprintf("gateway: error creating dir %s at the webdav endpoint: %s", ep.filePath, ep.endpoint))
}
return nil
}
Expand Down Expand Up @@ -132,7 +133,7 @@ func (s *svc) webdavRefMove(ctx context.Context, targetURL, src, destination str

err = c.Rename(srcEP.filePath, destEP.filePath, true)
if err != nil {
return errors.Wrap(err, "gateway: error calling rename at the webdav endpoint: "+srcEP.endpoint)
return errors.Wrap(err, fmt.Sprintf("gateway: error renaming %s to %s at the webdav endpoint: %s", srcEP.filePath, destEP.filePath, srcEP.endpoint))
}
return nil
}
Expand All @@ -152,7 +153,7 @@ func (s *svc) webdavRefDelete(ctx context.Context, targetURL string, nameQueries

err = c.Remove(ep.filePath)
if err != nil {
return errors.Wrap(err, "gateway: error calling remove at the webdav endpoint: "+ep.endpoint)
return errors.Wrap(err, fmt.Sprintf("gateway: error removing %s at the webdav endpoint: %s", ep.filePath, ep.endpoint))
}
return nil
}
Expand Down
10 changes: 7 additions & 3 deletions internal/http/services/dataprovider/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ func (s *svc) doTusPut(w http.ResponseWriter, r *http.Request) {
return
}

length, err := strconv.ParseInt(r.Header.Get("Upload-Length"), 10, 64)
length, err := strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
// Fallback to Upload-Length
length, err = strconv.ParseInt(r.Header.Get("Upload-Length"), 10, 64)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
}

dataServerURL := fmt.Sprintf("http://%s%s", r.Host, r.RequestURI)
Expand Down
12 changes: 8 additions & 4 deletions internal/http/services/owncloud/ocdav/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,20 @@ func (s *svc) handlePut(w http.ResponseWriter, r *http.Request, ns string) {
}
}

length, err := strconv.ParseInt(r.Header.Get("Upload-Length"), 10, 64)
length, err := strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
// Fallback to Upload-Length
length, err = strconv.ParseInt(r.Header.Get("Upload-Length"), 10, 64)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
}

opaqueMap := map[string]*typespb.OpaqueEntry{
"Upload-Length": {
Decoder: "plain",
Value: []byte(r.Header.Get("Upload-Length")),
Value: []byte(strconv.FormatInt(length, 10)),
},
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/localfs/localfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ func (fs *localfs) propagate(ctx context.Context, leafPath string) error {
}

parts := strings.Split(strings.TrimPrefix(leafPath, root), "/")
// root never ents in / so the split returns an empty first element, which we can skip
// root never ends in / so the split returns an empty first element, which we can skip
// we do not need to chmod the last element because it is the leaf path (< and not <= comparison)
for i := 1; i < len(parts); i++ {
if err := os.Chtimes(root, fi.ModTime(), fi.ModTime()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/token/manager/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/pkg/errors"
)

const defaultExpiration int64 = 3600 // 1 hour
const defaultExpiration int64 = 86400 // 1 day

func init() {
registry.Register("jwt", New)
Expand Down

0 comments on commit 97381a2

Please sign in to comment.