websvc

package
v0.0.0-...-b6e3791 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package websvc contains the AdGuard DNS web service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BindData

type BindData struct {
	// TLS is the optional TLS configuration.
	TLS *tls.Config

	// Address is the binding address.
	Address netip.AddrPort
}

BindData is data for binding one HTTP server to an address.

type BlockPageServer

type BlockPageServer struct {
	// Content is the content of the HTML block page.
	Content []byte

	// Bind are the addresses on which to serve the block page.
	Bind []*BindData
}

BlockPageServer is the safe browsing or adult blocking block page server configuration.

type Config

type Config struct {
	// SafeBrowsing is the optional safe browsing block page web server.
	SafeBrowsing *BlockPageServer

	// AdultBlocking is the optional adult blocking block page web server.
	AdultBlocking *BlockPageServer

	// LinkedIP is the optional linked IP web server.
	LinkedIP *LinkedIPServer

	// RootRedirectURL is the URL to which root HTTP requests are redirected.
	// If not set, these requests are responded with a 404 page.
	RootRedirectURL *url.URL

	// StaticContent is the content that is served statically at the given
	// paths.
	StaticContent StaticContent

	// DNSCheck is the HTTP handler for DNS checks.
	DNSCheck http.Handler

	// ErrColl is used to collect linked IP proxy errors and other errors.
	ErrColl errcoll.Interface

	// Error404 is the content of the HTML page for the 404 status.  If not set,
	// a simple plain text 404 response is served.
	Error404 []byte

	// Error500 is the content of the HTML page for the 500 status.  If not set,
	// a simple plain text 500 response is served.
	Error500 []byte

	// NonDoHBind are the bind addresses and optional TLS configuration for the
	// web service in addition to the ones in the DNS-over-HTTPS handlers.
	NonDoHBind []*BindData

	// Timeout is the timeout for all server operations.
	Timeout time.Duration
}

Config is the AdGuard DNS web service configuration structure.

type LinkedIPServer

type LinkedIPServer struct {
	// TargetURL is the URL to which linked IP API requests are proxied.
	TargetURL *url.URL

	// Bind are the addresses on which to serve the linked IP API.
	Bind []*BindData
}

LinkedIPServer is the linked IP server configuration.

type Service

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

Service is the AdGuard DNS web service. A nil *Service serves a simple plain-text 404 page.

func New

func New(c *Config) (svc *Service)

New returns a new properly initialized *Service. If c is nil, svc is a nil *Service that only serves a simple plain-text 404 page.

func (*Service) ServeHTTP

func (svc *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface for *Service.

func (*Service) Shutdown

func (svc *Service) Shutdown(ctx context.Context) (err error)

Shutdown implements the service.Interface interface for *Service. svc may be nil.

func (*Service) Start

func (svc *Service) Start(_ context.Context) (err error)

Start implements the service.Interface interface for *Service. It starts serving all endpoints but does not wait for them to actually go online. svc may be nil. err is always nil; if any endpoint fails to start, it panics.

TODO(a.garipov): Wait for the services to go online.

TODO(a.garipov): Use the context for cancelation.

type StaticContent

type StaticContent map[string]*StaticFile

StaticContent serves static content with the given content type.

type StaticFile

type StaticFile struct {
	// Headers contains headers of the HTTP response.
	Headers http.Header

	// Content is the file content.
	Content []byte
}

StaticFile is a single file in a StaticFS.

Jump to

Keyboard shortcuts

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