Repository navigation
Conversation
Add support for configuring the HTTP status code returned by the
blackhole outbound protocol when using HTTP response type.
This change allows users to specify a custom status code instead of
the hardcoded 403 Forbidden. Common use cases include:
- 204 No Content for captive portal/connectivity check responses
- 200 OK for custom HTTP responses
- 404 Not Found for stealth configurations
The default behavior (403 Forbidden) is preserved for backward
compatibility when no status code is specified.
Configuration example:
{
"outbounds": [{
"tag": "block-204",
"protocol": "blackhole",
"settings": {
"response": {
"type": "http",
"statusCode": 204
}
}
}]
}
Changes:
- Add status_code field to HTTPResponse message in config.proto
- Update WriteTo() method to use configured status code with
proper HTTP status text lookup
- Add statusCode JSON field support in infra/conf/blackhole.go
- Add comprehensive tests for various status codes
Co-authored-by: Cursor <[email protected]>
Member
|
我可能需要稍微整理一下这个出站 |
Contributor
Author
|
Thank you for reviewing! If you need any clarification on the implementation details or any help with this feature, please let me know — happy to assist. |
Member
|
我把它做成了这样 f49d8b8 不能配置code了但是可以自定义回复 |
Contributor
Author
|
Thank you for implementing this! The customResponseData approach is even more flexible — great solution. Looking forward to the next release. |
RPRX
pushed a commit
that referenced
this pull request
Sep 7, 2026
#6711 (comment) --------- Co-authored-by: Raaad1on <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for configuring the HTTP status code returned by the blackhole outbound protocol when using HTTP response type.
Problem
Currently, the blackhole protocol with HTTP response always returns
403 Forbidden. This limitation makes it unsuitable for several use cases:connectivitycheck.gstatic.com,captive.apple.com). These checks expect204 No Contentresponses to confirm connectivity.200 OKor404 Not Found.Solution
Add a
statusCodefield to the HTTP response configuration that allows specifying any valid HTTP status code. The default behavior (403 Forbidden) is preserved for backward compatibility when no status code is specified.Configuration Example
{ "outbounds": [{ "tag": "block-204", "protocol": "blackhole", "settings": { "response": { "type": "http", "statusCode": 204 } } }] }Use Case: Local Connectivity Check
{ "routing": { "rules": [{ "domain": [ "domain:gstatic.com", "domain:msftconnecttest.com", "domain:apple.com" ], "outboundTag": "connectivity-check" }] }, "outbounds": [{ "tag": "connectivity-check", "protocol": "blackhole", "settings": { "response": { "type": "http", "statusCode": 204 } } }] }Changes
status_codefield toHTTPResponsemessageWriteTo()method to use configured status code with proper HTTP status text lookup viahttp.StatusText()statusCodeJSON field support for configuration parsingBackward Compatibility
This change is fully backward compatible:
statusCodeis not specified (or set to 0), the default403 Forbiddenresponse is usedTesting
All existing tests pass, and new tests have been added to verify: