CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-h2

Pure-Python HTTP/2 protocol implementation providing low-level connection and stream management

Pending
Overview
Eval results
Files

configuration.mddocs/

Configuration

HTTP/2 connection configuration controlling validation, encoding, normalization, and logging behavior. Configuration provides fine-tuned control over protocol handling and allows customization for different use cases.

Capabilities

H2Configuration Class

Main configuration object controlling HTTP/2 connection behavior, header processing, validation rules, and logging.

class H2Configuration:
    def __init__(
        self,
        client_side: bool = True,
        header_encoding: str | None = None,
        validate_outbound_headers: bool = True,
        normalize_outbound_headers: bool = True,
        split_outbound_cookies: bool = False,
        validate_inbound_headers: bool = True,
        normalize_inbound_headers: bool = True,
        logger: DummyLogger | OutputLogger | None = None
    ):
        """
        Configure HTTP/2 connection behavior.
        
        Args:
            client_side: Whether connection is client-side (True) or server-side (False)
            header_encoding: Header encoding ('utf-8', None for bytes, False to disable)
            validate_outbound_headers: Validate outbound headers against RFC 7540
            normalize_outbound_headers: Normalize outbound headers before sending
            split_outbound_cookies: Split cookie headers for better compression
            validate_inbound_headers: Validate received headers
            normalize_inbound_headers: Normalize received headers
            logger: Logger instance for debugging
        """

Configuration Properties

@property
def client_side(self) -> bool:
    """Whether this connection is client-side or server-side."""

@property  
def header_encoding(self) -> str | None:
    """
    Header encoding configuration.
    
    Returns:
        None: Headers returned as bytes
        str: Encoding name (e.g., 'utf-8') for automatic string conversion
        False: Disable header encoding entirely
    """

@property
def validate_outbound_headers(self) -> bool:
    """Whether to validate outbound headers against RFC 7540 rules."""

@property
def normalize_outbound_headers(self) -> bool:
    """Whether to normalize outbound headers before sending."""

@property
def split_outbound_cookies(self) -> bool:
    """Whether to split outbound cookie headers for better compression."""

@property
def validate_inbound_headers(self) -> bool:
    """Whether to validate inbound headers against RFC 7540 rules."""

@property
def normalize_inbound_headers(self) -> bool:
    """Whether to normalize inbound headers after receiving."""

@property
def logger(self) -> DummyLogger | OutputLogger | None:
    """Logger instance for connection debugging."""

Logger Classes

Logging infrastructure for HTTP/2 connection debugging and tracing.

DummyLogger

No-operation logger that discards all log messages. Used when logging is not needed.

class DummyLogger:
    def __init__(self, *args): 
        """Initialize dummy logger that performs no logging."""

    def debug(self, *args, **kwargs) -> None:
        """No-op debug logging method."""

    def trace(self, *args, **kwargs) -> None:
        """No-op trace logging method."""

OutputLogger

Simple logger that outputs debug and trace messages to a file-like object (default stderr).

class OutputLogger:
    def __init__(self, file=None, trace_level: bool = False):
        """
        Initialize output logger.
        
        Args:
            file: File-like object to write to (default: stderr)
            trace_level: Whether to enable trace-level logging
        """

    def debug(self, fmtstr: str, *args) -> None:
        """
        Log debug message.
        
        Args:
            fmtstr: Format string
            *args: Format arguments
        """

    def trace(self, fmtstr: str, *args) -> None:
        """
        Log trace message (if trace_level enabled).
        
        Args:
            fmtstr: Format string  
            *args: Format arguments
        """

Configuration Usage Examples

Client Configuration

from h2.config import H2Configuration

# Basic client configuration
config = H2Configuration(client_side=True)

# Client with UTF-8 header encoding
config = H2Configuration(
    client_side=True,
    header_encoding='utf-8'
)

# Strict client with full validation
config = H2Configuration(
    client_side=True,
    validate_outbound_headers=True,
    validate_inbound_headers=True,  
    normalize_outbound_headers=True,
    normalize_inbound_headers=True
)

Server Configuration

from h2.config import H2Configuration, OutputLogger

# Basic server configuration
config = H2Configuration(client_side=False)

# Server with logging enabled
logger = OutputLogger(trace_level=True)
config = H2Configuration(
    client_side=False,
    logger=logger
)

# Server with cookie splitting for better compression
config = H2Configuration(
    client_side=False,
    split_outbound_cookies=True
)

Development and Debugging Configuration

from h2.config import H2Configuration, OutputLogger
import sys

# Configuration for debugging with trace logging
logger = OutputLogger(file=sys.stdout, trace_level=True)
config = H2Configuration(
    client_side=True,
    header_encoding='utf-8',
    logger=logger
)

# Permissive configuration for testing
config = H2Configuration(
    client_side=True,
    validate_outbound_headers=False,
    validate_inbound_headers=False,
    normalize_outbound_headers=False,
    normalize_inbound_headers=False
)

Configuration Effects

Header Processing

Configuration controls how headers are processed:

  • validate_outbound_headers: Checks headers conform to RFC 7540 before sending
  • normalize_outbound_headers: Converts header names to lowercase, validates format
  • split_outbound_cookies: Splits cookie headers on ; boundaries for HPACK compression
  • validate_inbound_headers: Validates received headers against RFC 7540 rules
  • normalize_inbound_headers: Normalizes received header format
  • header_encoding: Controls whether headers are returned as bytes or decoded strings

Client vs Server Behavior

The client_side setting affects:

  • Stream ID assignment (odd for client, even for server)
  • Connection initiation behavior
  • Push promise handling (clients receive, servers send)
  • Default settings values
  • State machine behavior

Logging Integration

Logger configuration enables debugging of:

  • Frame processing
  • State transitions
  • Header validation
  • Flow control operations
  • Protocol violations

Install with Tessl CLI

npx tessl i tessl/pypi-h2

docs

configuration.md

connection.md

events.md

exceptions.md

index.md

settings.md

tile.json