@@ -105,12 +105,14 @@ func (s *Server) getObjectFile(key string, generation int64) ([]byte, error) {
105105}
106106
107107func (s * Server ) handler (w http.ResponseWriter , r * http.Request ) {
108+ uri := strings .TrimPrefix (r .RequestURI , "/storage/v1" )
109+
108110 switch {
109111 // Handle Bucket metadata related queries
110- case strings .HasPrefix (r . RequestURI , "/b/" ):
112+ case strings .HasPrefix (uri , "/b/" ):
111113 switch {
112114 // Return metadata about the Bucket
113- case r . RequestURI == fmt .Sprintf ("/b/%s?alt=json&prettyPrint=false&projection=full" , s .BucketName ):
115+ case uri == fmt .Sprintf ("/b/%s?alt=json&prettyPrint=false&projection=full" , s .BucketName ):
114116 etag := md5 .New ()
115117 for _ , v := range s .Objects {
116118 etag .Write (v .Content )
@@ -125,12 +127,12 @@ func (s *Server) handler(w http.ResponseWriter, r *http.Request) {
125127 w .Write (jsonResponse )
126128 return
127129 // Return metadata about a Bucket object
128- case strings .Contains (r . RequestURI , "/o/" ):
130+ case strings .Contains (uri , "/o/" ):
129131 var obj * Object
130132 for _ , o := range s .Objects {
131133 // The object key in the URI is escaped.
132134 // e.g.: /b/dummy/o/included%2Ffile.txt?alt=json&prettyPrint=false&projection=full
133- if r . RequestURI == fmt .Sprintf ("/b/%s/o/%s?alt=json&prettyPrint=false&projection=full" , s .BucketName , url .QueryEscape (o .Key )) {
135+ if uri == fmt .Sprintf ("/b/%s/o/%s?alt=json&prettyPrint=false&projection=full" , s .BucketName , url .QueryEscape (o .Key )) {
134136 obj = o
135137 break
136138 }
@@ -149,7 +151,7 @@ func (s *Server) handler(w http.ResponseWriter, r *http.Request) {
149151 w .WriteHeader (404 )
150152 return
151153 // Return metadata about all objects in the Bucket
152- case strings .Contains (r . RequestURI , "/o?" ):
154+ case strings .Contains (uri , "/o?" ):
153155 response := s .getAllObjects ()
154156 jsonResponse , err := json .Marshal (response )
155157 if err != nil {
@@ -166,7 +168,7 @@ func (s *Server) handler(w http.ResponseWriter, r *http.Request) {
166168 // Handle object file query
167169 default :
168170 bucketPrefix := fmt .Sprintf ("/%s/" , s .BucketName )
169- if strings .HasPrefix (r . RequestURI , bucketPrefix ) {
171+ if strings .HasPrefix (uri , bucketPrefix ) {
170172 // The URL path is of the format /<bucket>/included/file.txt.
171173 // Extract the object key by discarding the bucket prefix.
172174 key := strings .TrimPrefix (r .URL .Path , bucketPrefix )
0 commit comments