Add "HEAD" method in File API

Description

Dear awesome community!

I'm currently using File API but we can't check that the file exists.

CRUD is fully respected with:

  • POST: create
  • GET: read
  • PUT: update
  • DELETE: delete

Proposal

Add "HEAD"

The HTTP HEAD method requests the headers that are returned if the specified resource would be requested with an HTTP GET method. Such a request can be done before deciding to download a large resource to save bandwidth.

But HEAD doesn't return a body so we could put information in headers.

Like AWS S3 add some metadata like GET returns

GET

curl --request GET --header 'PRIVATE-TOKEN: mytoken' "https://mygitlab.com/api/v4/projects/myprojectid/repository/files/myfile?ref=master" | jq. 
{
  "file_name": "myfile",
  "file_path": "myfile",
  "size": 1639,
  "encoding": "base64",
  "content": "xxxxxxxxxxxxxxxxxx",
  "content_sha256": "xxxxxxxxxxxzzzzzzzzz",
  "ref": "master",
  "blob_id": "5bc3288f340f81215ce6b8a049ec14f8f6268193",
  "commit_id": "84061bbad73d0b3a2a598f43599355a4871034af",
  "last_commit_id": "78181ed46d6d8c489dcc96ec1fd5a8bb11a52a8d"
}

HEAD (empty body, only http headers)

curl -v --request HEAD --header 'PRIVATE-TOKEN: mytoken' "https://mygitlab.com/api/v4/projects/myprojectid/repository/files/myfile?ref=master" | jq. 
...
"x-gitlab-file_name": "myfile",
"x-gitlab-file_path": "myfile",
"x-gitlab-size": 1639,
"x-gitlab-encoding": "base64",
"x-gitlab-ref": "master",
"x-gitlab-blob_id": "5bc3288f340f81215ce6b8a049ec14f8f6268193",
"x-gitlab-commit_id": "84061bbad73d0b3a2a598f43599355a4871034af",
"x-gitlab-last_commit_id": "78181ed46d6d8c489dcc96ec1fd5a8bb11a52a8d",
"x-gitlab-content_sha256": "xxxxxxxxxxx"
...

where x-gitlab-content-sha256 is the sha256 of the file, see proposal #47315 (closed)

Links / references

http head: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD aws s3: https://docs.aws.amazon.com/AmazonS3/latest/API/RESTCommonRequestHeaders.html

Edited by Ahmet Demir