@@ -105,12 +105,14 @@ func (s *Server) getObjectFile(key string, generation int64) ([]byte, error) {
105
105
}
106
106
107
107
func (s * Server ) handler (w http.ResponseWriter , r * http.Request ) {
108
+ uri := strings .TrimPrefix (r .RequestURI , "/storage/v1" )
109
+
108
110
switch {
109
111
// Handle Bucket metadata related queries
110
- case strings .HasPrefix (r . RequestURI , "/b/" ):
112
+ case strings .HasPrefix (uri , "/b/" ):
111
113
switch {
112
114
// 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 ):
114
116
etag := md5 .New ()
115
117
for _ , v := range s .Objects {
116
118
etag .Write (v .Content )
@@ -125,12 +127,12 @@ func (s *Server) handler(w http.ResponseWriter, r *http.Request) {
125
127
w .Write (jsonResponse )
126
128
return
127
129
// Return metadata about a Bucket object
128
- case strings .Contains (r . RequestURI , "/o/" ):
130
+ case strings .Contains (uri , "/o/" ):
129
131
var obj * Object
130
132
for _ , o := range s .Objects {
131
133
// The object key in the URI is escaped.
132
134
// 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 )) {
134
136
obj = o
135
137
break
136
138
}
@@ -149,7 +151,7 @@ func (s *Server) handler(w http.ResponseWriter, r *http.Request) {
149
151
w .WriteHeader (404 )
150
152
return
151
153
// Return metadata about all objects in the Bucket
152
- case strings .Contains (r . RequestURI , "/o?" ):
154
+ case strings .Contains (uri , "/o?" ):
153
155
response := s .getAllObjects ()
154
156
jsonResponse , err := json .Marshal (response )
155
157
if err != nil {
@@ -166,7 +168,7 @@ func (s *Server) handler(w http.ResponseWriter, r *http.Request) {
166
168
// Handle object file query
167
169
default :
168
170
bucketPrefix := fmt .Sprintf ("/%s/" , s .BucketName )
169
- if strings .HasPrefix (r . RequestURI , bucketPrefix ) {
171
+ if strings .HasPrefix (uri , bucketPrefix ) {
170
172
// The URL path is of the format /<bucket>/included/file.txt.
171
173
// Extract the object key by discarding the bucket prefix.
172
174
key := strings .TrimPrefix (r .URL .Path , bucketPrefix )
0 commit comments