Skip to content

web: serve all requests from Flamego and remove Macaron - #8542

Merged
unknwon merged 3 commits into
mainfrom
flamego-server
Nov 17, 2026
Merged

unknwon merged 3 commits into
mainfrom
flamego-server

Conversation

@unknwon

@unknwon unknwon commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Describe the pull request

Part 3 of 3 of removing Macaron: Flamego now serves every request, and gopkg.in/macaron.v1 and all github.com/go-macaron/* modules are removed from go.mod.

  • newRoutingHandler is the top-level handler. It runs the request logger, recovery, the nosniff and X-Frame-Options headers, the static files (custom public, embedded public, user and repository avatars), the localizer and the cache, then the routes. It takes the localizer, the session middleware and the authenticator as arguments, so the access tests supply the viewer without a database. Gzip ([server] ENABLE_GZIP) wraps it with klauspost/compress/gzhttp, and the fcgi subpath is trimmed in a Before hook.
  • /healthcheck, /-/metrics, Git over HTTP and LFS are mounted before the session middleware, so they still never create a session. Every other route runs the cross-origin protection, session.Sessioner, authenticator (the same session, token, reverse proxy and basic authentication as before), the CORS headers and the captcha.
  • Sessions use flamego/session with the memory, file and Redis providers from [session]. It saves a session only when the request changed it, like Macaron's session did, and refreshes the expiry of a session that is only read.
  • Signing in still moves the session to a new ID and deletes the old session, so a session ID planted before signing in is not signed in.
  • API v1 is still served by its own handler behind apiV1Bridger, which now takes the user, the authentication method and the locale from Flamego. apiV1Access replaces the Toggle middleware for API v1 with the same responses. Unknown API v1 routes and server errors still render the 404 and 500 pages of the web app.
  • API v1 validates request bodies itself instead of with go-macaron/binding, for the rules its requests use (Required, AlphaDashDot, Email, Size, MaxSize, In, OmitEmpty). Binding errors keep the same JSON fields, classifications and status codes (400, 415 and 422).
  • internal/i18n replaces go-macaron/i18n with the same language choice: the lang query parameter (remembered in a cookie, then redirected), the lang cookie, then Accept-Language.
  • Removed: context.Contexter, context.Toggle, context.Context, flamegoBridger, flamegoInjector, flamegoSessionAdapter, the Macaron renderer, internal/form/form.go (the go-macaron binding rules) and internal/mocks/locale.go. Mail takes the locale instead of *macaron.Context.
  • The integration tests read sessions with flamego/session, and the route coverage check lists Flamego routes only.
  • Also carries repo: wrap long words in commit message bodies #8606 and web: draw Mermaid diagrams in rendered Markdown #8620, which were merged into this branch.

Fixes #7503
Fixes #7562

Behavior changes from legacy

  • New session IDs are 16 lowercase letters and digits instead of 16 hex digits. Existing session IDs and the data stored by the file and Redis providers stay readable, so users stay signed in across the upgrade (verified with the file provider).
  • The prefix option of the Redis session provider is not supported by flamego/session. It is ignored with a warning, so with a prefix configured, users sign in again after the upgrade.
  • The request log lines have Flamego's format.

Screenshots

No UI changes. Pages after this change, served by a -tags prod build:

Signed in Repository
Dashboard Repository
?lang=zh-CN Unknown API v1 route
Repository in Chinese Not found page
Dark mode 375px
Commits in dark mode Repository at 375px

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code and provided the test plan below.
  • I have added an entry to CHANGELOG.

Test plan

  1. go test ./cmd/... ./internal/... passes and moon run gogs:lint reports 0 issues. The access tests of the web API run through the whole routing handler, session middleware included. The session fixation test runs on flamego/session with the memory and file providers.
  2. The integration tests pass with -shuffle=on, including the check that every route has a test: Git over HTTP and SSH, Git LFS with the git lfs client, the web API and API v1.
  3. Compared the new API v1 validation with go-macaron/binding on 990 values across all 15 request types: the JSON of the errors is the same for every value. Making MaxSize inclusive, skipping AlphaDashDot or changing a message each made the comparison fail.
  4. Against a -tags prod build: signing in through the form changes the session ID and the old ID is not signed in, signing out expires the cookie and the old ID gets 401, and an anonymous visitor gets one session cookie, not one per request.
  5. API v1: access tokens, basic authentication on the token routes, binding errors (400, 415, 422, a form value that is not a boolean), a trailing slash, and the 404 page for an unknown route. A token is ignored by the web API.
  6. ?lang=zh-CN sets the cookie and redirects to the same path. With ENABLE_GZIP = true, assets are compressed. Cross-site POSTs to the web API get 403, and nosniff and X-Frame-Options are set.

@unknwon unknwon mentioned this pull request Nov 13, 2026
3 of 4 tasks
@unknwon
unknwon added this pull request to stack #8457 November 13, 2026 15:32
// Matches go-macaron's Redis adapters: any non-empty `tls=` value enables
// TLS with InsecureSkipVerify.
config.Options.TLSConfig = &tls.Config{InsecureSkipVerify: true}
opts.tlsConfig = &tls.Config{InsecureSkipVerify: true}
Comment on lines +306 to +310
http.SetCookie(w, &http.Cookie{
Name: conf.Security.LoginStatusCookieName,
Value: "true",
Path: cmp.Or(conf.Server.Subpath, "/"),
})
Comment on lines +306 to +310
http.SetCookie(w, &http.Cookie{
Name: conf.Security.LoginStatusCookieName,
Value: "true",
Path: cmp.Or(conf.Server.Subpath, "/"),
})
Comment on lines +519 to +525
http.SetCookie(w, &http.Cookie{
Name: conf.Session.CookieName,
Path: cmp.Or(conf.Server.Subpath, "/"),
HttpOnly: true,
Expires: time.Now(),
MaxAge: -1,
})
Comment thread internal/i18n/i18n.go
Comment on lines +100 to +105
http.SetCookie(c.ResponseWriter(), &http.Cookie{
Name: "lang",
Value: url.QueryEscape(lang),
Path: "/" + strings.TrimPrefix(subURL, "/"),
MaxAge: 1<<31 - 1,
})
@unknwon
unknwon force-pushed the flamego-server branch 2 times, most recently from 6c144ea to 9131558 Compare November 14, 2026 05:43
@unknwon
unknwon force-pushed the flamego-server branch 2 times, most recently from 34ec33f to a53bf7b Compare November 14, 2026 16:03
@unknwon
unknwon force-pushed the flamego-server branch 3 times, most recently from 1592054 to 5a2664f Compare November 14, 2026 18:49
@unknwon
unknwon force-pushed the flamego-server branch 7 times, most recently from f6f30f5 to a7abd1e Compare November 14, 2026 23:00
@mintlify

mintlify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
Gogs 🟢 Ready View Preview Nov 17, 2026, 1:32 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@unknwon
unknwon merged commit e4cb183 into main Nov 17, 2026
14 of 15 checks passed
@unknwon
unknwon deleted the flamego-server branch November 17, 2026 13:53

This branch was successfully deployed

1 active deployment
staging - docs — 50826ffe Deployed Nov 17, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP 404 for "Browse Source" with shortened SHA hash showing massive diff output, ignoring Diff lines limit (for a single file) setting

2 participants