Support URL requests through active core outbounds - #205
Open
eliotcougar wants to merge 5 commits into
Open
Conversation
eliotcougar
marked this pull request as ready for review
August 18, 2026 14:32
eliotcougar
marked this pull request as draft
August 18, 2026 14:50
Author
|
Follow-up correction in 16b52e1: This explicit contract also makes the API suitable for future subscription and resource-file downloads through the running core: those callers can select the intended outbound instead of inheriting user routing accidentally. |
eliotcougar
marked this pull request as ready for review
August 18, 2026 14:58
eliotcougar
marked this pull request as draft
August 18, 2026 15:25
eliotcougar
marked this pull request as ready for review
August 18, 2026 15:51
Add CoreController.GetUrlContent to perform bounded HTTP GET requests with core.Dial. This lets Android callers retrieve response bodies through the running Xray instance without depending on a local proxy inbound. The API is intended for xray-tun connection metadata and can also support resource or subscription downloads that should follow the active core route.
GetUrlContent previously passed requests to core.Dial without an outbound override, allowing normal routing rules to send platform-initiated downloads through direct or another detour. Accept an explicit outbound tag and attach it to every dial with Xray session metadata. This preserves dispatcher-managed connections while ensuring redirects and retries continue through the caller-selected outbound.
Add CoreController.GetBalancerPrincipleTarget using Xray's existing routing feature and return the first viable strategy target. This gives Android callers a concrete outbound for policy-group requests without requiring a custom Xray-core API.
eliotcougar
force-pushed
the
codex/xray-tun-connection-info
branch
from
August 20, 2026 08:19
12f008b to
4e640ec
Compare
Add a binary-safe URL download API that uses the active core and an explicitly selected outbound. Accept request headers and a caller-defined timeout, stream successful responses directly to disk, and remove partial files on failure.
Write responses to a sibling temporary file and replace the destination only after a complete transfer. Reject unsolicited partial-content responses and verify declared response lengths so truncation or write failures leave existing files intact.
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
CoreController.GetUrlContentfor bounded text requests through the running Xray instanceCoreController.DownloadUrlToFilefor header-aware, binary-safe streaming to diskWhy
Android callers sometimes need to reuse the already-running Xray connection when no local proxy listener exists. The initial use is v2rayNG's current-connection test in native Xray TUN mode, where the configured connection-info URL supplies the displayed country code and IP address.
Calling
core.Dialwithout selecting an outbound is insufficient: normal routing rules may send an app-initiated request throughdirector another detour. The result would then describe the wrong connection. Large subscriptions and binary resource files also should not be returned as strings or passed through Binder.Downstream use
v2rayNG #6109 uses these APIs to:
balancer-mainto a concrete member for primary policy groupsOrdinary profiles pass the
proxyoutbound. Policy groups use the first non-empty principle target exposed by Xray's existing routing feature. Strategies with several principle candidates remain best-effort; querying the target does not advance random or round-robin state.The file-download API is intentionally general and can be reused by other Android callers that need subscriptions or resources to follow an existing Xray-core connection.
Implementation
The shared request helper snapshots the running core instance, applies
session.SetForcedOutboundTagToContextinsideDialContext, and opens connections withcore.Dial. Redirects therefore remain on the requested outbound.DownloadUrlToFileaccepts request headers and a caller-defined timeout. It streams the response to a mode-0600sibling temporary file, verifies a declaredContent-Length, closes the file, and then replaces the destination withos.Rename. Read, write, close, or rename failures remove only the temporary file, preserving any existing destination.Unsolicited HTTP 206 responses are rejected because the helper never sends a Range request. Other successful 2xx responses remain supported.
The implementation is confined to
libv2ray_utils.go;libv2ray_main.gois unchanged.Validation
go test ./...gomobile bindAAR build:armeabi-v7a,arm64-v8a,x86, andx86_64HttpUtilTest