Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not support "HEAD" http request #8030

Closed
gonboy opened this issue Aug 29, 2019 · 4 comments
Closed

not support "HEAD" http request #8030

gonboy opened this issue Aug 29, 2019 · 4 comments
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/proposal The new feature has not been accepted yet but needs to be discussed first.

Comments

@gonboy
Copy link

gonboy commented Aug 29, 2019

sometime, I want use gitea as file web server.
so need to download it. if not support HEAD to get the file size.
so can't calc the left time

@sapk
Copy link
Member

sapk commented Aug 29, 2019

Can you provide a example url on try.gitea ?

@bwenrich
Copy link
Contributor

bwenrich commented Sep 1, 2019

If I understand correctly, the intention is to determine the size of the object that would be sent, so a client application could generate a progress-bar of the download progress.

My quick testing shows that Gitea didn't provide the "Content-Length" attribute in the HTTP response header, so the client does not know the response size in advance.

# Example from an arbitrary file on try.gitea.io
$ curl --head https://try.gitea.io/gitea/gitea/src/branch/master/README.md
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Sun, 01 Sep 2019 03:01:40 GMT
set-cookie: lang=en-US; Path=/; Max-Age=2147483647
set-cookie: i_like_gitea=<<removed>>; Path=/; HttpOnly
set-cookie: _csrf=<<removed>>; Path=/; Expires=Mon, 02 Sep 2019 03:01:40 GMT; HttpOnly
x-frame-options: SAMEORIGIN
# Example from a generic Apache server
$ curl --head https://domain.example.com/README.md
HTTP/1.1 200 OK
Date: Sun, 01 Sep 2019 03:04:17 GMT
Last-Modified: Sun, 18 Aug 2019 02:25:17 GMT
Accept-Ranges: bytes
Content-Length: 5934
content-type: text/html; charset=UTF-8

The Content-Length attribute is not mandatory for HTTP HEAD or HTTP GET, but could be useful in some cases.

@stale
Copy link

stale bot commented Oct 31, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale stale bot added the issue/stale label Oct 31, 2019
@lunny lunny added the type/proposal The new feature has not been accepted yet but needs to be discussed first. label Nov 2, 2019
@stale stale bot removed the issue/stale label Nov 2, 2019
@lunny lunny added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label Nov 2, 2019
faridtsl added a commit to faridtsl/gitea that referenced this issue Feb 1, 2021
This change adds the header Content-Length to HEAD HTTP requests.

The previous behaviour was blocking some Windows executables (i.e
bitsadmin.exe) from downloading files hosted in Gitea.

This along with PR go-gitea#14541, makes the web server compliant with HTTP RFC 2616 which states
"The methods GET and HEAD MUST be supported by all general-purpose servers"
and
"The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response."

This should also respond to issues go-gitea#8030 and go-gitea#14532.
@6543
Copy link
Member

6543 commented Feb 5, 2021

did #14541 close this issue?

6543 pushed a commit that referenced this issue Feb 5, 2021
* Add Content-Length header to HEAD requests

This change adds the header Content-Length to HEAD HTTP requests.

The previous behaviour was blocking some Windows executables (i.e
bitsadmin.exe) from downloading files hosted in Gitea.

This along with PR #14541, makes the web server compliant with HTTP RFC 2616 which states
"The methods GET and HEAD MUST be supported by all general-purpose servers"
and
"The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response."

This should also respond to issues #8030 and #14532.

* This change adds the header Content-Length to HEAD HTTP requests

Pass the Size of the content as a parameter to ServeData() instead of
calculating it using ioutil.ReadAll(reader) --> this call is dangerous
and can result in a denial of service.

* Add Content-Length header to HEAD requests

Quick fix for imported dependency not used.

* Check if size is positiv int ...

Co-authored-by: zeripath <[email protected]>
@lunny lunny closed this as completed Feb 8, 2021
@go-gitea go-gitea locked and limited conversation to collaborators Mar 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/proposal The new feature has not been accepted yet but needs to be discussed first.
Projects
None yet
Development

No branches or pull requests

5 participants