fix: /api/forgejo/v1/version Content-Type error (#9897)

fix: #9782
## Checklist

The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org).

### Tests

- I added test coverage for Go changes...
  - [ ] in their respective `*_test.go` for unit tests.
  - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server.
- I added test coverage for JavaScript changes...
  - [ ] in `web_src/js/*.test.js` if it can be unit tested.
  - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)).

### Documentation

- [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change.
- [ ] I did not document these changes and I do not expect someone else to do it.

### Release notes

- [ ] I do not want this change to show in the release notes.
- [ ] I want the title to show in the release notes with a link to this pull request.
- [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9897
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: Cyborus <cyborus@noreply.codeberg.org>
Co-authored-by: fnoopv <fnoopv@noreply.codeberg.org>
Co-committed-by: fnoopv <fnoopv@noreply.codeberg.org>
This commit is contained in:
fnoopv
2025-11-05 17:35:50 +01:00
committed by Mathieu Fenniak
parent ec7dc193b4
commit b98c8f696c
2 changed files with 8 additions and 0 deletions
+1
View File
@@ -18,6 +18,7 @@ func NewForgejo() *Forgejo {
}
func (f *Forgejo) GetVersion(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(Version{&setting.ForgejoVersion})
}
@@ -29,6 +29,13 @@ func TestAPIForgejoVersion(t *testing.T) {
assert.Equal(t, "1.0.0", *version.Version)
})
t.Run("Version with Content-Type is json", func(t *testing.T) {
req := NewRequest(t, "GET", "/api/forgejo/v1/version")
resp := MakeRequest(t, req, http.StatusOK)
assert.Equal(t, "application/json; charset=utf-8", resp.Header().Get("Content-Type"))
})
t.Run("Versions with REQUIRE_SIGNIN_VIEW enabled", func(t *testing.T) {
defer test.MockVariableValue(&setting.Service.RequireSignInView, true)()
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()