|
|
@ -47,6 +47,7 @@ type storageRESTServer struct { |
|
|
|
func (s *storageRESTServer) writeErrorResponse(w http.ResponseWriter, err error) { |
|
|
|
func (s *storageRESTServer) writeErrorResponse(w http.ResponseWriter, err error) { |
|
|
|
w.WriteHeader(http.StatusForbidden) |
|
|
|
w.WriteHeader(http.StatusForbidden) |
|
|
|
w.Write([]byte(err.Error())) |
|
|
|
w.Write([]byte(err.Error())) |
|
|
|
|
|
|
|
w.(http.Flusher).Flush() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Authenticates storage client's requests and validates for skewed time.
|
|
|
|
// Authenticates storage client's requests and validates for skewed time.
|
|
|
@ -93,6 +94,7 @@ func (s *storageRESTServer) GetInstanceID(w http.ResponseWriter, r *http.Request |
|
|
|
} |
|
|
|
} |
|
|
|
w.Header().Set("Content-Length", strconv.Itoa(len(s.instanceID))) |
|
|
|
w.Header().Set("Content-Length", strconv.Itoa(len(s.instanceID))) |
|
|
|
w.Write([]byte(s.instanceID)) |
|
|
|
w.Write([]byte(s.instanceID)) |
|
|
|
|
|
|
|
w.(http.Flusher).Flush() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DiskInfoHandler - returns disk info.
|
|
|
|
// DiskInfoHandler - returns disk info.
|
|
|
@ -268,6 +270,7 @@ func (s *storageRESTServer) ReadAllHandler(w http.ResponseWriter, r *http.Reques |
|
|
|
} |
|
|
|
} |
|
|
|
w.Header().Set("Content-Length", strconv.Itoa(len(buf))) |
|
|
|
w.Header().Set("Content-Length", strconv.Itoa(len(buf))) |
|
|
|
w.Write(buf) |
|
|
|
w.Write(buf) |
|
|
|
|
|
|
|
w.(http.Flusher).Flush() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ReadFileHandler - read section of a file.
|
|
|
|
// ReadFileHandler - read section of a file.
|
|
|
@ -311,6 +314,7 @@ func (s *storageRESTServer) ReadFileHandler(w http.ResponseWriter, r *http.Reque |
|
|
|
} |
|
|
|
} |
|
|
|
w.Header().Set("Content-Length", strconv.Itoa(len(buf))) |
|
|
|
w.Header().Set("Content-Length", strconv.Itoa(len(buf))) |
|
|
|
w.Write(buf) |
|
|
|
w.Write(buf) |
|
|
|
|
|
|
|
w.(http.Flusher).Flush() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ReadFileHandler - read section of a file.
|
|
|
|
// ReadFileHandler - read section of a file.
|
|
|
@ -331,6 +335,7 @@ func (s *storageRESTServer) ReadFileStreamHandler(w http.ResponseWriter, r *http |
|
|
|
s.writeErrorResponse(w, err) |
|
|
|
s.writeErrorResponse(w, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rc, err := s.storage.ReadFileStream(volume, filePath, int64(offset), int64(length)) |
|
|
|
rc, err := s.storage.ReadFileStream(volume, filePath, int64(offset), int64(length)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
s.writeErrorResponse(w, err) |
|
|
|
s.writeErrorResponse(w, err) |
|
|
@ -338,7 +343,9 @@ func (s *storageRESTServer) ReadFileStreamHandler(w http.ResponseWriter, r *http |
|
|
|
} |
|
|
|
} |
|
|
|
defer rc.Close() |
|
|
|
defer rc.Close() |
|
|
|
w.Header().Set("Content-Length", strconv.Itoa(length)) |
|
|
|
w.Header().Set("Content-Length", strconv.Itoa(length)) |
|
|
|
|
|
|
|
|
|
|
|
io.Copy(w, rc) |
|
|
|
io.Copy(w, rc) |
|
|
|
|
|
|
|
w.(http.Flusher).Flush() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ListDirHandler - list a directory.
|
|
|
|
// ListDirHandler - list a directory.
|
|
|
|