tlsserver

package
v0.0.0-...-43a846b Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package tlsserver with TLS server for use by plugins and testing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBearerToken

func GetBearerToken(req *http.Request) (string, error)

GetBearerToken returns the bearer token from the HTTP request authorization header Returns an error if no token present or token isn't a bearer token

func WriteError

func WriteError(w http.ResponseWriter, err error, code int)

WriteError is a convenience function that logs and writes an error If the reply has an error then write a bad request with the error as payload This also writes the StatusHeader containing StatusFailed.

func WriteReply

func WriteReply(
	w http.ResponseWriter, handled bool, data any, err error)

WriteReply is a convenience function that serializes the data and writes it as a response, optionally reporting an error with code BadRequest.

when handled, this returns a 200 status code if no error is returned. handled is false means the request is in progress. This returns a 201. if an err is returned this returns a 400 bad request or 403 unauthorized error code the data can contain error details.

Types

type TLSServer

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

TLSServer is a simple TLS MsgServer supporting BASIC, Jwt and client certificate authentication

func NewTLSServer

func NewTLSServer(address string, port int,
	serverCert *tls.Certificate,
	caCert *x509.Certificate,
) (*TLSServer, *chi.Mux)

NewTLSServer creates a new TLS MsgServer instance with authentication support. This returns the chi-go router which can be used to add routes and middleware. This server supports the "message-id" header for received requests.

Use Start() to start listening.

The middleware handlers included with the server can be used for authentication.

address        server listening address
port           listening port
serverCert     Server TLS certificate
caCert         CA certificate to verify client certificates

returns TLS server and router for handling requests

func (*TLSServer) Router

func (srv *TLSServer) Router() *chi.Mux

Router returns the router for this server. This router has cors protection enabled.

func (*TLSServer) Start

func (srv *TLSServer) Start() error

Start the TLS server using the provided CA and Server certificates. If a client certificate is provided it must be valid and signed by the CA. This configures handling of CORS requests to allow:

  • any origin by returning the requested origin (not using wildcard '*').
  • any method, eg PUT, POST, GET, PATCH,
  • headers "Origin", "Accept", "Content-Type", "X-Requested-With"

func (*TLSServer) Stop

func (srv *TLSServer) Stop()

Stop the TLS server and close all connections this waits until for up to 3 seconds for connections are closed. After that continue.

Jump to

Keyboard shortcuts

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