Skip to content

Implement the prereadable connection - #47

Open
weiiwang01 wants to merge 1 commit into
mainfrom
ng/preread-conn
Open

Implement the prereadable connection#47
weiiwang01 wants to merge 1 commit into
mainfrom
ng/preread-conn

Conversation

@weiiwang01

@weiiwang01 weiiwang01 commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Stack created with GitHub Stacks CLIGive Feedback 💬

This is a part of a series of pull requests to create the next generation of the aproxy.

In this pull request, the core utility that enables the extraction of SNI or host name from a connection (prereadable connection) is implemented.

@weiiwang01
weiiwang01 marked this pull request as ready for review August 17, 2026 06:29
@weiiwang01
weiiwang01 requested a review from a team as a code owner August 17, 2026 06:29
@weiiwang01
weiiwang01 requested review from swetha1654 and yanksyoon and removed request for a team August 17, 2026 06:29
@florentianayuwono
florentianayuwono requested a lite review from Copilot August 17, 2026 09:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Implements a new internal conn package that wraps *net.TCPConn to support a “preread” mode: reads are buffered and can be rewound/replayed so callers can sniff initial bytes (e.g., SNI/Host) without losing stream integrity.

Changes:

  • Added internal/conn.Conn with preread buffering, rewind, preread limit enforcement, and optional metrics hooks.
  • Added an extensive test suite covering limit behavior, replay boundaries, EOF handling, and concurrency invariants.
  • Updated module Go version and dependency set.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
internal/conn/conn.go Adds the preread-capable TCPConn wrapper, options, and metrics hooks.
internal/conn/conn_test.go Adds comprehensive unit tests for preread/replay/limit/EOF and concurrency behaviors.
go.mod Updates Go version and introduces new module requirements/indirect requirements.
go.sum Adds checksums for new/updated module dependencies.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/conn/conn.go
if m == nil {
panic("nil metrics")
}
if v := reflect.ValueOf(m); v.Kind() == reflect.Pointer && v.IsNil() {
Comment thread go.mod
Comment on lines +3 to 4
go 1.25.0

Comment thread internal/conn/conn.go

const defaultPrereadLimit = 64 * 1024

var ErrPrereadLimitExceeded = errors.New("exceed preread limit")
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