http_server

package
v0.0.0-...-df25031 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 34 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const MaxDecodedRequestBytes = 32 << 20

MaxDecodedRequestBytes caps how much a single request body may decode to.

A compressed body is a size multiplier whose factor the sender chooses: DEFLATE tops out near 1000:1, zstd and brotli have no comparable ceiling, so without a cap a few hundred kilobytes on the wire can ask nodecore to hold gigabytes - from anyone who can reach the port. The window cap in internal/compression bounds what one frame header can make a decoder allocate; this bounds what the decoded bytes themselves can.

32MiB is far above anything JSON-RPC produces in practice - a batch of ten thousand calls is on the order of a megabyte - so it is a ceiling on abuse rather than a limit real traffic meets.

It is the cap that applies when server.limits.max-request-size is not set. A configured limit takes its place - see Decompress.

Variables

This section is empty.

Functions

func ArraySortingStream

func ArraySortingStream(ctx context.Context, data <-chan *Response, expected int) io.Reader

func Compress

func Compress() echo.MiddlewareFunc

Compress returns a middleware that compresses the response body with the coding the client asked for - zstd, br or gzip, whichever Negotiate picks. A client that asks for neither is served plain bytes.

func Decompress

func Decompress(maxRequestBytes int64) echo.MiddlewareFunc

Decompress returns a middleware that decodes a compressed request body, so handlers always read plain bytes whatever the client sent, and bounds how much of a body a handler may read. Codings nodecore does not speak are passed through untouched rather than guessed at.

maxRequestBytes is server.limits.max-request-size. Zero means it is not set, and then only a body nodecore actually decodes is capped, at MaxDecodedRequestBytes - bytes on the wire are bytes the client had to send in full, which is its own limit. A positive value bounds every body as it arrives, and a decoded body a second time on what it decodes to, in place of MaxDecodedRequestBytes. Both bounds are needed: a decoded size says little about the wire, since a coding may carry any amount of framing that decodes to nothing - empty gzip members, skippable zstd frames.

func HandleWebsocket

func HandleWebsocket(
	ctx context.Context,
	conn *websocket.Conn,
	chain string,
	authPayload auth.AuthPayload,
	appCtx *server_ctx.ApplicationServerContext,
	limits *config.LimitsConfig,
	routingSelectors []protocol.RequestSelector,
)

func NewHttpServer

func NewHttpServer(appCtx *server_ctx.ApplicationServerContext) *echo.Echo

NewHttpServer builds the handler for client traffic. It is served by an EchoServer created with WithClientLimits.

func NewSortingReader

func NewSortingReader(ctx context.Context, data <-chan *Response, expected int) io.Reader

func WithClientLimits

func WithClientLimits(ctx context.Context) func(*http.Server)

WithClientLimits is the EchoServer option for the server that takes client traffic: every request context descends from ctx, and the connection deadlines are set.

Types

type DropLastReader

type DropLastReader struct {
	// contains filtered or unexported fields
}

func (*DropLastReader) Read

func (d *DropLastReader) Read(buf []byte) (int, error)

type EchoServer

type EchoServer struct {
	// contains filtered or unexported fields
}

EchoServer serves an echo instance: echo is only an http.Handler, the http.Server around it belongs to whoever runs it.

echo.StartConfig is deliberately not used for that. It shuts the server down on its own when a context ends, which takes away the order nodecore stops its servers in; it reads the certificate through an fs.FS, which rejects the absolute paths `server.tls` is normally given; and it puts a 30s read timeout on every server it starts.

func NewEchoServer

func NewEchoServer(e *echo.Echo, options ...func(*http.Server)) *EchoServer

NewEchoServer wraps e in a server with net/http's defaults. Options adjust that server before it starts.

func (*EchoServer) Shutdown

func (s *EchoServer) Shutdown(ctx context.Context) error

Shutdown stops accepting connections and waits for the requests in flight until ctx ends.

func (*EchoServer) Start

func (s *EchoServer) Start(addr string, tlsCfg *config.TlsConfig) error

Start listens on addr and serves until Shutdown, which makes it return http.ErrServerClosed. With TLS enabled the connection is offered both h2 and http/1.1, the latter being what a WebSocket handshake needs.

type FastJSONSerializer

type FastJSONSerializer struct{}

func (FastJSONSerializer) Deserialize

func (FastJSONSerializer) Deserialize(c *echo.Context, i any) error

func (FastJSONSerializer) Serialize

func (FastJSONSerializer) Serialize(c *echo.Context, i any, indent string) error

type JsonRpcHandler

type JsonRpcHandler struct {
	// contains filtered or unexported fields
}

func NewJsonRpcHandler

func NewJsonRpcHandler(preReq *server_ctx.Request, requestBody io.Reader, isWsCtx bool, maxBatchSize int) (*JsonRpcHandler, error)

NewJsonRpcHandler parses a JSON-RPC body - a single request or a batch. maxBatchSize is server.limits.max-batch-size: a batch with more items is rejected in RequestDecode. Zero means no limit.

func (*JsonRpcHandler) GetRequestType

func (j *JsonRpcHandler) GetRequestType() protocol.RequestType

func (*JsonRpcHandler) IsSingle

func (j *JsonRpcHandler) IsSingle() bool

func (*JsonRpcHandler) RequestCount

func (j *JsonRpcHandler) RequestCount() int

func (*JsonRpcHandler) RequestDecode

func (j *JsonRpcHandler) RequestDecode(ctx context.Context) (*server_ctx.Request, error)

func (*JsonRpcHandler) ResponseEncode

func (j *JsonRpcHandler) ResponseEncode(response protocol.ResponseHolder) *Response

type RequestHandler

type RequestHandler interface {
	RequestDecode(context.Context) (*server_ctx.Request, error)
	ResponseEncode(response protocol.ResponseHolder) *Response
	IsSingle() bool
	RequestCount() int
	GetRequestType() protocol.RequestType
}

type Response

type Response struct {
	ResponseReader io.Reader
	Order          int
}

type RestHandler

type RestHandler struct {
	// contains filtered or unexported fields
}

func NewRestHandler

func NewRestHandler(preReq *server_ctx.Request, req *http.Request, restPath string) (*RestHandler, error)

NewRestHandler builds a REST handler from an incoming HTTP request. restPath is the path under /queries/{chain}/ (already URL-decoded by echo, with the query string stripped). The query string and headers are carried on req so the parser can promote them into RequestParams. For GETs and other no-body verbs the request body is allowed to be empty; only non-empty bodies are validated as JSON so callers like algod's REST API don't get rejected at parse time.

func (*RestHandler) GetRequestType

func (r *RestHandler) GetRequestType() protocol.RequestType

func (*RestHandler) IsSingle

func (r *RestHandler) IsSingle() bool

func (*RestHandler) RequestCount

func (r *RestHandler) RequestCount() int

func (*RestHandler) RequestDecode

func (r *RestHandler) RequestDecode(_ context.Context) (*server_ctx.Request, error)

func (*RestHandler) ResponseEncode

func (r *RestHandler) ResponseEncode(response protocol.ResponseHolder) *Response

type SingleByteReader

type SingleByteReader []byte

func (SingleByteReader) Read

func (r SingleByteReader) Read(buf []byte) (int, error)

type SortingReader

type SortingReader struct {
	// contains filtered or unexported fields
}

func (*SortingReader) Read

func (a *SortingReader) Read(buf []byte) (int, error)

Jump to

Keyboard shortcuts

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