From b98c8f696c0c2aa51b933b6f5821afa594e474d7 Mon Sep 17 00:00:00 2001 From: fnoopv Date: Wed, 5 Nov 2025 17:35:50 +0100 Subject: [PATCH] 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/.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 Reviewed-by: Cyborus Co-authored-by: fnoopv Co-committed-by: fnoopv --- routers/api/forgejo/v1/forgejo.go | 1 + tests/integration/api_forgejo_version_test.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/routers/api/forgejo/v1/forgejo.go b/routers/api/forgejo/v1/forgejo.go index b63db6fb9a..c9df36b983 100644 --- a/routers/api/forgejo/v1/forgejo.go +++ b/routers/api/forgejo/v1/forgejo.go @@ -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}) } diff --git a/tests/integration/api_forgejo_version_test.go b/tests/integration/api_forgejo_version_test.go index b42e4a2bd7..e3a1bbd9ac 100644 --- a/tests/integration/api_forgejo_version_test.go +++ b/tests/integration/api_forgejo_version_test.go @@ -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())()