You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

7 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
3 years ago
3 years ago
  1. package s3api
  2. import (
  3. "encoding/base64"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/s3api/s3err"
  6. "google.golang.org/grpc"
  7. "net/http"
  8. "github.com/chrislusf/seaweedfs/weed/pb"
  9. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  10. )
  11. var _ = filer_pb.FilerClient(&S3ApiServer{})
  12. func (s3a *S3ApiServer) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
  13. return pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
  14. client := filer_pb.NewSeaweedFilerClient(grpcConnection)
  15. return fn(client)
  16. }, s3a.option.Filer.ToGrpcAddress(), s3a.option.GrpcDialOption)
  17. }
  18. func (s3a *S3ApiServer) AdjustedUrl(location *filer_pb.Location) string {
  19. return location.Url
  20. }
  21. func writeSuccessResponseXML(w http.ResponseWriter, r *http.Request, response interface{}) {
  22. s3err.WriteXMLResponse(w, r, http.StatusOK, response)
  23. }
  24. func writeSuccessResponseEmpty(w http.ResponseWriter, r *http.Request) {
  25. s3err.WriteEmptyResponse(w, r, http.StatusOK)
  26. }
  27. func validateContentMd5(h http.Header) ([]byte, error) {
  28. md5B64, ok := h["Content-Md5"]
  29. if ok {
  30. if md5B64[0] == "" {
  31. return nil, fmt.Errorf("Content-Md5 header set to empty value")
  32. }
  33. return base64.StdEncoding.DecodeString(md5B64[0])
  34. }
  35. return []byte{}, nil
  36. }