s3api_handlers.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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(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(), 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. s3err.PostLog(r, http.StatusOK, s3err.ErrNone)
  24. }
  25. func writeSuccessResponseEmpty(w http.ResponseWriter, r *http.Request) {
  26. s3err.WriteEmptyResponse(w, r, http.StatusOK)
  27. }
  28. func validateContentMd5(h http.Header) ([]byte, error) {
  29. md5B64, ok := h["Content-Md5"]
  30. if ok {
  31. if md5B64[0] == "" {
  32. return nil, fmt.Errorf("Content-Md5 header set to empty value")
  33. }
  34. return base64.StdEncoding.DecodeString(md5B64[0])
  35. }
  36. return []byte{}, nil
  37. }