@@ -102,7 +102,7 @@ func (a *App) QueryHandler(key []byte, w http.ResponseWriter, r *http.Request) {
102102 }
103103}
104104
105- func (a * App ) Delete (key []byte , unlink bool ) int {
105+ func (a * App ) Delete (key []byte , unlink bool , auth string ) int {
106106 // delete the key, first locally
107107 rec := a .GetRecord (key )
108108 if rec .deleted == HARD || (unlink && rec .deleted == SOFT ) {
@@ -123,7 +123,7 @@ func (a *App) Delete(key []byte, unlink bool) int {
123123 delete_error := false
124124 for _ , volume := range rec .rvolumes {
125125 remote := fmt .Sprintf ("http://%s%s" , volume , key2path (key ))
126- if remote_delete (remote ) != nil {
126+ if remote_delete (remote , auth ) != nil {
127127 // if this fails, it's possible to get an orphan file
128128 // but i'm not really sure what else to do?
129129 delete_error = true
@@ -142,7 +142,7 @@ func (a *App) Delete(key []byte, unlink bool) int {
142142 return 204
143143}
144144
145- func (a * App ) WriteToReplicas (key []byte , value io.Reader , valuelen int64 ) int {
145+ func (a * App ) WriteToReplicas (key []byte , value io.Reader , valuelen int64 , auth string ) int {
146146 // we don't have the key, compute the remote URL
147147 kvolumes := key2volume (key , a .volumes , a .replicas , a .subvolumes , a .vdir_colocation )
148148
@@ -160,7 +160,7 @@ func (a *App) WriteToReplicas(key []byte, value io.Reader, valuelen int64) int {
160160 body = bytes .NewReader (buf .Bytes ())
161161 }
162162 remote := fmt .Sprintf ("http://%s%s" , kvolumes [i ], key2path (key ))
163- if remote_put (remote , valuelen , body ) != nil {
163+ if remote_put (remote , valuelen , body , auth ) != nil {
164164 // we assume the remote wrote nothing if it failed
165165 fmt .Printf ("replica %d write failed: %s\n " , i , remote )
166166 // try not to leave key in INIT (writing) state (ignore errors)
@@ -188,6 +188,7 @@ func (a *App) WriteToReplicas(key []byte, value io.Reader, valuelen int64) int {
188188func (a * App ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
189189 key := []byte (r .URL .Path )
190190 lkey := []byte (r .URL .Path + r .URL .Query ().Get ("partNumber" ))
191+ auth := r .Header .Get ("Authorization" )
191192
192193 log .Println (r .Method , r .URL , r .ContentLength , r .Header ["Range" ])
193194
@@ -237,7 +238,7 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
237238 good := false
238239 for _ , vn := range rand .Perm (len (rec .rvolumes )) {
239240 remote = fmt .Sprintf ("http://%s%s" , rec .rvolumes [vn ], key2path (key ))
240- found , _ := remote_head (remote , a .voltimeout )
241+ found , _ := remote_head (remote , a .voltimeout , auth )
241242 if found {
242243 good = true
243244 break
@@ -285,7 +286,7 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
285286
286287 for _ , subkey := range del .Keys {
287288 fullkey := fmt .Sprintf ("%s/%s" , key , subkey )
288- status := a .Delete ([]byte (fullkey ), false )
289+ status := a .Delete ([]byte (fullkey ), false , auth )
289290 if status != 204 {
290291 w .WriteHeader (status )
291292 return
@@ -324,7 +325,7 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
324325 fs = append (fs , f )
325326 }
326327
327- status := a .WriteToReplicas (key , io .MultiReader (fs ... ), sz )
328+ status := a .WriteToReplicas (key , io .MultiReader (fs ... ), sz , auth )
328329 w .WriteHeader (status )
329330 w .Write ([]byte ("<CompleteMultipartUploadResult></CompleteMultipartUploadResult>" ))
330331 return
@@ -363,11 +364,11 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
363364 io .Copy (f , r .Body )
364365 w .WriteHeader (200 )
365366 } else {
366- status := a .WriteToReplicas (key , r .Body , r .ContentLength )
367+ status := a .WriteToReplicas (key , r .Body , r .ContentLength , auth )
367368 w .WriteHeader (status )
368369 }
369370 case "DELETE" , "UNLINK" :
370- status := a .Delete (key , r .Method == "UNLINK" )
371+ status := a .Delete (key , r .Method == "UNLINK" , auth )
371372 w .WriteHeader (status )
372373 case "RELINK" :
373374 rec := a .GetRecord (key )
@@ -391,7 +392,7 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
391392 }
392393
393394 kvolumes := key2volume (key , a .volumes , a .replicas , a .subvolumes , a .vdir_colocation )
394- rbreq := RebalanceRequest {key : key , volumes : rec .rvolumes , kvolumes : kvolumes }
395+ rbreq := RebalanceRequest {key : key , volumes : rec .rvolumes , kvolumes : kvolumes , auth : auth }
395396 if ! rebalance (a , rbreq ) {
396397 w .WriteHeader (400 )
397398 return
0 commit comments