// Copyright 2026 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.27 && !http2legacy

// Server wrapping a net/http.Server.

package http2

import (
	
	
	
	
	
	
	
	
)

type serverInternalState struct {
	s1            *http.Server
	initOnce      sync.Once
	serveConnFunc func(context.Context, net.Conn, http.Handler, bool, *http.Request, []byte)
}

func ( *http.Server,  *Server) error {
	if  == nil {
		panic("nil *http.Server")
	}
	if  == nil {
		 = new(Server)
	}
	if .state != nil {
		// This isn't a panic in the pre-wrapping implementation,
		// but calling ConfigureServer twice with the same http2.Server
		// overwrites internal state on the server.
		// Make the error explicit and early here.
		panic("ConfigureServer may be called only once per Server")
	}
	if ,  := , ; .IdleTimeout == 0 {
		if .IdleTimeout != 0 {
			.IdleTimeout = .IdleTimeout
		} else {
			.IdleTimeout = .ReadTimeout
		}
	}

	// Register h2 and http/1.1 ALPN protocols on s.TLSConfig, matching
	// the pre-wrapping implementation in server.go, so that TLS listeners
	// built from s.TLSConfig still negotiate HTTP/2.
	if .TLSConfig == nil {
		.TLSConfig = new(tls.Config)
	}
	if !slices.Contains(.TLSConfig.NextProtos, NextProtoTLS) {
		.TLSConfig.NextProtos = append(.TLSConfig.NextProtos, NextProtoTLS)
	}
	if !slices.Contains(.TLSConfig.NextProtos, "http/1.1") {
		.TLSConfig.NextProtos = append(.TLSConfig.NextProtos, "http/1.1")
	}

	.state = &serverInternalState{
		s1: ,
	}
	 := &serverConfig{s: }
	if  := .Serve();  != nil || .serveConnFunc == nil {
		panic("http2: net/http does not support this version of x/net/http2")
	}
	.state.serveConnFunc = .serveConnFunc
	return nil
}

type serverConfig struct {
	s             *Server
	serveConnFunc func(context.Context, net.Conn, http.Handler, bool, *http.Request, []byte)
}

func (*serverConfig) () (net.Conn, error) {
	return nil, errors.New("unexpected call to Accept")
}
func (*serverConfig) () error {
	return nil
}
func (*serverConfig) () net.Addr {
	return nil
}

func ( *serverConfig) ( func(context.Context, net.Conn, http.Handler, bool, *http.Request, []byte)) {
	.serveConnFunc = 
}

func ( *serverConfig) () http.HTTP2Config {
	return http.HTTP2Config{
		MaxConcurrentStreams:          int(.s.MaxConcurrentStreams),
		MaxDecoderHeaderTableSize:     int(.s.MaxDecoderHeaderTableSize),
		MaxEncoderHeaderTableSize:     int(.s.MaxEncoderHeaderTableSize),
		MaxReadFrameSize:              int(.s.MaxReadFrameSize),
		PermitProhibitedCipherSuites:  .s.PermitProhibitedCipherSuites,
		MaxReceiveBufferPerConnection: int(.s.MaxUploadBufferPerConnection),
		MaxReceiveBufferPerStream:     int(.s.MaxUploadBufferPerStream),
		SendPingTimeout:               .s.ReadIdleTimeout,
		PingTimeout:                   .s.PingTimeout,
		WriteByteTimeout:              .s.WriteByteTimeout,
		CountError:                    .s.CountError,
	}
}

func ( *serverConfig) () time.Duration {
	return .s.IdleTimeout
}

type serverConn struct{}

func ( *Server) ( net.Conn,  *ServeConnOpts,  func(*serverConn)) {
	var  func(context.Context, net.Conn, http.Handler, bool, *http.Request, []byte)
	switch {
	case .BaseConfig != nil:
		// The user has provided us with an http.Server to take configuration from.
		//
		// We can't send our request to opts.BaseConfig, because an http.Server can
		// only be associated with a single http2.Server and the user might
		// use this one with several http.Servers.
		//
		// We can't send our request to s.state.s1, because it doesn't contain
		// the right configuration.
		//
		// So create a one-off copy of opts.BaseConfig and use it.
		 := &http.Server{
			TLSConfig:         .BaseConfig.TLSConfig,
			ReadTimeout:       .BaseConfig.ReadTimeout,
			ReadHeaderTimeout: .BaseConfig.ReadHeaderTimeout,
			WriteTimeout:      .BaseConfig.WriteTimeout,
			IdleTimeout:       .BaseConfig.IdleTimeout,
			MaxHeaderBytes:    .BaseConfig.MaxHeaderBytes,
			ConnState:         .BaseConfig.ConnState,
			ErrorLog:          .BaseConfig.ErrorLog,
			BaseContext:       .BaseConfig.BaseContext,
			ConnContext:       .BaseConfig.ConnContext,
			HTTP2:             .BaseConfig.HTTP2,
		}
		 := &serverConfig{s: }
		if  := .Serve();  != nil || .serveConnFunc == nil {
			panic("http2: net/http does not support this version of x/net/http2")
		}
		 = .serveConnFunc
	case .state != nil:
		 = .state.serveConnFunc
	default:
		// Strange-but-true: Server has no concurrency-safe way to initialize
		// its internal state, so historically ServeConn just doesn't use any
		// persistent state if you don't call ConfigureServer first.
		//
		// If ConfigureServer hasn't been called, create a one-off http.Server
		// for the connection, since we don't have any way to keep one around for reuse.
		 := &http.Server{}
		 := &serverConfig{s: }
		if  := .Serve();  != nil || .serveConnFunc == nil {
			panic("http2: net/http does not support this version of x/net/http2")
		}
		 = .serveConnFunc
	}

	,  := serverConnBaseContext(, )
	defer ()
	(, , .handler(), .SawClientPreface, .UpgradeRequest, .Settings)

}

// FrameWriteRequest is a request to write a frame.
//
// Deprecated: User-provided write schedulers are deprecated.
type FrameWriteRequest struct {
	// Ideally we'd define this in writesched_common.go,
	// to avoid duplicating an exported symbol across two files,
	// but the changes required to make this work are fairly large.
}

func ( FrameWriteRequest) () uint32 {
	return 0
}

func ( FrameWriteRequest) () int {
	return 0
}

func ( FrameWriteRequest) ( int32) (FrameWriteRequest, FrameWriteRequest, int) {
	return FrameWriteRequest{}, FrameWriteRequest{}, 0
}

func ( FrameWriteRequest) () string {
	return ""
}

// NewPriorityWriteScheduler is deprecated.
//
// Deprecated: User-provided write schedulers are deprecated.
func ( *PriorityWriteSchedulerConfig) WriteScheduler {
	return unsupportedWriteScheduler{}
}

// NewRandomWriteScheduler is deprecated.
//
// Deprecated: User-provided write schedulers are deprecated.
func () WriteScheduler {
	return unsupportedWriteScheduler{}
}

type unsupportedWriteScheduler struct{}

func (unsupportedWriteScheduler) ( uint32,  OpenStreamOptions) {}
func (unsupportedWriteScheduler) ( uint32)                           {}
func (unsupportedWriteScheduler) ( uint32,  PriorityParam)  {}
func (unsupportedWriteScheduler) ( FrameWriteRequest)                             {}
func (unsupportedWriteScheduler) () ( FrameWriteRequest,  bool) {
	return FrameWriteRequest{}, false
}