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.

52 lines
1.4 KiB

7 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. "net/http"
  6. "github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
  7. "google.golang.org/grpc"
  8. "github.com/seaweedfs/seaweedfs/weed/pb"
  9. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  10. )
  11. var _ = filer_pb.FilerClient(&S3ApiServer{})
  12. func (s3a *S3ApiServer) WithFilerClient(streamingMode bool, fn func(filer_pb.SeaweedFilerClient) error) error {
  13. return pb.WithGrpcClient(streamingMode, func(grpcConnection *grpc.ClientConn) error {
  14. client := filer_pb.NewSeaweedFilerClient(grpcConnection)
  15. return fn(client)
  16. }, s3a.option.Filer.ToGrpcAddress(), false, s3a.option.GrpcDialOption)
  17. }
  18. func (s3a *S3ApiServer) AdjustedUrl(location *filer_pb.Location) string {
  19. return location.Url
  20. }
  21. func (s3a *S3ApiServer) GetDataCenter() string {
  22. return s3a.option.DataCenter
  23. }
  24. func writeSuccessResponseXML(w http.ResponseWriter, r *http.Request, response interface{}) {
  25. s3err.WriteXMLResponse(w, r, http.StatusOK, response)
  26. s3err.PostLog(r, http.StatusOK, s3err.ErrNone)
  27. }
  28. func writeSuccessResponseEmpty(w http.ResponseWriter, r *http.Request) {
  29. s3err.WriteEmptyResponse(w, r, http.StatusOK)
  30. }
  31. func validateContentMd5(h http.Header) ([]byte, error) {
  32. md5B64, ok := h["Content-Md5"]
  33. if ok {
  34. if md5B64[0] == "" {
  35. return nil, fmt.Errorf("Content-Md5 header set to empty value")
  36. }
  37. return base64.StdEncoding.DecodeString(md5B64[0])
  38. }
  39. return []byte{}, nil
  40. }