detect

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package detect provides HTTP protocol detection from initial connection bytes.

Index

Constants

View Source
const MinPeekBytes = 4

MinPeekBytes is the minimum number of bytes needed to begin detection.

View Source
const PrefaceLen = len(frame.ClientPreface)

PrefaceLen is the full HTTP/2 client connection preface length.

Variables

View Source
var (
	// ErrInsufficientData indicates not enough bytes for detection.
	ErrInsufficientData = errors.New("insufficient data for protocol detection")
	// ErrUnknownProtocol indicates the data does not match any known protocol.
	ErrUnknownProtocol = errors.New("unknown protocol")
)

Functions

func Detect

func Detect(buf []byte) (engine.Protocol, error)

Detect examines the initial bytes of a connection and returns the detected protocol.

Detection logic:

  1. If len(buf) < 4, return ErrInsufficientData.
  2. If first 4 bytes are "PRI ", this may be HTTP/2. Need 24 bytes total. If we have 24 bytes and they match ClientPreface -> engine.H2C If we have < 24 bytes -> ErrInsufficientData (need more data) If 24 bytes don't match -> ErrUnknownProtocol
  3. If first byte is a known HTTP method start character -> engine.HTTP1
  4. Otherwise -> ErrUnknownProtocol

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL