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

HTTP HEAD requests (eg. curl -I) not supported on the API #18543

Closed
qwerty287 opened this issue Feb 2, 2022 · 11 comments
Closed

HTTP HEAD requests (eg. curl -I) not supported on the API #18543

qwerty287 opened this issue Feb 2, 2022 · 11 comments
Labels
issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail

Comments

@qwerty287
Copy link
Contributor

qwerty287 commented Feb 2, 2022

Gitea Version

Tried on codeberg.org and gitea.com

How are you running Gitea?

Only tried on Codeberg and gitea.com

Can you reproduce the bug on the Gitea demo site?

Yes

Description

Gitea returns an 405 error if trying to use curl with the -I option (only view headers).

Screenshots

No response

@zeripath
Copy link
Contributor

zeripath commented Feb 2, 2022

Could you give an example of an URL which returns 405?

I suspect that this is not coming from gitea but from the proxies in front of Gitea.

@zeripath zeripath added the issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail label Feb 2, 2022
@qwerty287
Copy link
Contributor Author

@qwerty287 qwerty287 changed the title Can't use curl -I Can't use curl -I with API Feb 2, 2022
@zeripath zeripath changed the title Can't use curl -I with API HTTP HEAD requests not supported on the API Feb 2, 2022
@zeripath zeripath changed the title HTTP HEAD requests not supported on the API HTTP HEAD requests (eg. curl -I) not supported on the API Feb 2, 2022
@zeripath
Copy link
Contributor

zeripath commented Feb 2, 2022

OK so curl -I is HTTP HEAD - so really your query is about HEAD requests not being supported on the API.

Could you explain why you want to use HEAD on the API?

@qwerty287
Copy link
Contributor Author

qwerty287 commented Feb 2, 2022

My usecase was to find out the http headers of a list (e.g. link and x-total-count).
Instead I had to use curl -i.

@wxiaoguang
Copy link
Contributor

Is this still a problem? IMO by design Gitea API doesn't support general HEAD method.

@vasishath
Copy link

vasishath commented Jul 19, 2022

But according to this reply in issue #2081, HEAD request was supported by API atleast at that time.

But it returns 405 now

A valid use case for this is that gradle uses this request when fetching maven packages from package registry. Without that, it doesn't work. See this issue.

@Jaffex
Copy link

Jaffex commented Aug 11, 2022

Can confirm the issue with the package repository:

Gradle uses HEAD calls to determine if the remote package has changed since the last download to determine if it has to download it again.

According to this comment in the issue mentioned by @vasishath over at gradle, package repositories that don't allow HEAD calls are not planned to be supported.

So currently if I try to use the gitea package repository with gradle, I'll get the error

Could not HEAD 'https://example.com/package/repository/version/package.pom'. Received status code 405 from server: Method Not Allowed

@afoo
Copy link

afoo commented Nov 15, 2022

Just got really excited for the new package repository feature for a minute, until I found out it's unusable for us in its current state because all our projects use gradle, which, as @Jaffex pointed out, is not and will never be possible as long as the repository does not support HEAD requests.

@zeripath does that answer your question why somebody would want this supported?

The issue still has the state "needs feedback". What feedback do you need to be able to decide how to proceed?

@zeripath
Copy link
Contributor

OK so we need to implement Head support for these package endpoints. Is it just the package endpoints that need this? Do we just need to support this for some of these endpoints and not all of them? Which ones?

The current way we hand HEAD requests is to essentially perform the GET which may be quite expensive on the API in general. So it would be helpful to avoid having to do that in general.

@KN4CK3R do you have any ideas here?

@KN4CK3R
Copy link
Member

KN4CK3R commented Nov 16, 2022

The package registries are implemented according their spec. If there is no HEAD endpoint, I did not implement one. For Maven there is no (public) spec, at least I could not find one, so it was mostly doing something with mvn and see what requests were received by Gitea. There were no HEAD requests, so I didn't know there was something missing.

Out of curiosity @afoo @Jaffex : Did you try gradle with the Gitlab Maven registry? I don't see HEAD in their spec too: https://docs.gitlab.com/ee/api/packages/maven.html
Looks like it's supported without explicitly implementing it.

I will create a PR for the maven registry part.

lafriks pushed a commit that referenced this issue Nov 24, 2022
Related #18543

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
KN4CK3R added a commit to KN4CK3R/gitea that referenced this issue Nov 24, 2022
Related go-gitea#18543

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
@lunny lunny closed this as completed Mar 29, 2023
@lunny
Copy link
Member

lunny commented Mar 29, 2023

It should be fixed.

$ curl -I https://gitea.com/api/v1/version
HTTP/2 405
date: Wed, 29 Mar 2023 06:15:27 GMT
cache-control: max-age=0, private, must-revalidate, no-transform
vary: Origin
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN

@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail
Projects
None yet
Development

No branches or pull requests

8 participants