s3api_handlers.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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.FilerGrpcAddress, 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, response interface{}) {
  22. s3err.WriteXMLResponse(w, http.StatusOK, response)
  23. }
  24. func writeSuccessResponseEmpty(w http.ResponseWriter) {
  25. s3err.WriteEmptyResponse(w, 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. }