Skip to content

Commit

Permalink
lxd/instance/file: Add type and size to HEAD (from Incus) (canonical#…
Browse files Browse the repository at this point in the history
…13904)

cherry picked from lxc/incus#383
  • Loading branch information
tomponline authored Aug 10, 2024
2 parents 4a3d573 + 1eb95e1 commit 96043b1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lxd/instance_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func instanceFileGet(s *state.State, inst instance.Instance, path string, r *htt
fileType = "symlink"
}

fs := stat.Sys().(*sftp.FileStat)
fs, _ := stat.Sys().(*sftp.FileStat)

// Prepare the response.
headers := map[string]string{
Expand Down Expand Up @@ -339,7 +339,7 @@ func instanceFileHead(inst instance.Instance, path string) response.Response {
fileType = "symlink"
}

fs := stat.Sys().(*sftp.FileStat)
fs, _ := stat.Sys().(*sftp.FileStat)

// Prepare the response.
headers := map[string]string{
Expand All @@ -350,6 +350,11 @@ func instanceFileHead(inst instance.Instance, path string) response.Response {
"X-LXD-type": fileType,
}

if fileType == "file" {
headers["Content-Type"] = "application/octet-stream"
headers["Content-Length"] = fmt.Sprintf("%d", stat.Size())
}

// Return an empty body (per RFC for HEAD).
return response.ManualResponse(func(w http.ResponseWriter) error {
// Set the headers.
Expand Down

0 comments on commit 96043b1

Please sign in to comment.