Skip to content

feat(vhost): support custom error pages via server config - #5610

Open
Tommickey2020gmail wants to merge 1 commit into
fatedier:devfrom
Tommickey2020gmail:feat/custom-error-pages
Open

Tommickey2020gmail wants to merge 1 commit into
fatedier:devfrom
Tommickey2020gmail:feat/custom-error-pages

Conversation

@Tommickey2020gmail

Copy link
Copy Markdown

Summary

Adds a new customErrorPages option to the frps config that lets users customize the error responses frps generates itself, using inline content in the config file — no HTML files need to be mounted into the frps container/image.

This complements the existing custom404Page (file path) option:

  • custom404Page still works and takes precedence for 404 responses.
  • customErrorPages covers any 4xx/5xx status code frps can emit on the vhost ports: 404 (no route found), 504 (proxy timeout — previously an empty body), 401 (vhost basic auth), 407 (proxy auth).
  • Each entry supports statusCode, contentType (default text/html), inline body, and extra headers (e.g. Retry-After).

Example (frps.toml):

[[customErrorPages]]
statusCode = 404
contentType = "text/html"
body = """
<!DOCTYPE html>
<html><body>
<h1>Page not found</h1>
<p>Need help? Contact support@example.com</p>
</body></html>
"""

[[customErrorPages]]
statusCode = 504
body = "Service temporarily unavailable, please try again later."
[customErrorPages.headers]
Retry-After = "30"

Use case: operators who expose frps vhost ports directly (e.g. in Docker) can brand the error page to match their own system and show support contact info, without building custom images or running a reverse proxy in front.

Test plan

  • go test ./pkg/util/vhost ./pkg/config/... — new unit tests in pkg/util/vhost/resource_test.go cover precedence (file > inline > default), custom headers/content type, and NotFoundResponse
  • go vet clean
  • Verified TOML parsing end-to-end via config.LoadServerConfig (strict mode), including multi-line body and [customErrorPages.headers]
  • E2E: not added; the change only affects response bodies on existing error paths

Add customErrorPages to the frps config so users can customize error
responses generated by frps itself (404 no route, 504 proxy timeout,
401/407 auth failed) with inline body content, without mounting files
into the container.

For status code 404, the existing custom404Page file takes precedence
over a customErrorPages entry.
# statusCode = 504
# contentType = "text/html"
# body = "Service temporarily unavailable, please try again later."
# [customErrorPages.headers]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Move the error-page examples below the remaining root settings

Uncommenting these examples in their current location leaves TOML inside [customErrorPages.headers], so the following udpPacketSize = 1500 and natholeAnalysisDataReserveHours = 168 become response-header entries instead of server settings. Configuration loading then fails because CustomErrorPage.Headers is a map[string]string but those values are numbers, even with strict parsing disabled. Enabling only the 404 example also captures those settings inside its array element and fails default strict parsing. Move the entire example block after the remaining root/dotted settings, immediately before [[httpPlugins]], so enabling this documented option does not prevent frps from starting.

@kilo-code-bot

kilo-code-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
conf/frps_full_example.toml 180 Uncommenting the error-page examples captures subsequent root settings inside the error-page table, causing configuration loading to fail. Move the examples after all root/dotted settings, before [[httpPlugins]].
Files Reviewed (7 files)
  • conf/frps_full_example.toml - 1 issue
  • pkg/config/v1/server.go - 0 issues
  • pkg/config/v1/validation/server.go - 0 issues
  • pkg/util/vhost/http.go - 0 issues
  • pkg/util/vhost/resource.go - 0 issues
  • pkg/util/vhost/resource_test.go - 0 issues
  • server/service.go - 0 issues

Static review of all changed files at 9212c75d8aac3d53dc5b393394bba52811739222. No code or tests were executed, as required by read-only review mode.

Fix these issues in Kilo Cloud


Reviewed by gpt-6.1-sol · Input: 45 · Output: 6.1K · Cached: 694.6K

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.

2 participants