echo_plugin

package
v0.0.0-...-12b7791 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ForbiddenPortMap = map[int]struct{}{
	1:    {},
	7:    {},
	9:    {},
	11:   {},
	13:   {},
	15:   {},
	17:   {},
	19:   {},
	20:   {},
	21:   {},
	22:   {},
	23:   {},
	25:   {},
	37:   {},
	42:   {},
	43:   {},
	53:   {},
	77:   {},
	79:   {},
	80:   {},
	87:   {},
	95:   {},
	101:  {},
	102:  {},
	103:  {},
	104:  {},
	109:  {},
	110:  {},
	111:  {},
	113:  {},
	115:  {},
	117:  {},
	119:  {},
	123:  {},
	135:  {},
	139:  {},
	143:  {},
	179:  {},
	389:  {},
	465:  {},
	512:  {},
	513:  {},
	514:  {},
	515:  {},
	526:  {},
	530:  {},
	531:  {},
	532:  {},
	540:  {},
	556:  {},
	563:  {},
	587:  {},
	601:  {},
	636:  {},
	993:  {},
	995:  {},
	2049: {},
	3659: {},
	4045: {},
	6000: {},
	6665: {},
	6666: {},
	6667: {},
	6668: {},
	6669: {},
	6697: {},
}

Functions

func Copy

func Copy(hs *EchoServer, dst io.Writer, src io.Reader) (written int64, err error)

func CopyN

func CopyN(hs *EchoServer, dst io.Writer, src io.Reader, n int64) (written int64, err error)

CopyN copies n bytes (or until an error) from src to dst. It returns the number of bytes copied and the earliest error encountered while copying. On return, written == n if and only if err == nil.

If dst implements the ReaderFrom interface, the copy is implemented using it.

func Init

func Init(serverConfig Config, OnPanicHanlder func(panic_err interface{}), logger log.Logger) error

func Init_

func Init_(name string, serverConfig Config, OnPanicHanlder func(panic_err interface{}), logger log.Logger) error

Init a new instance.

If only need one instance, use empty name "". Use GetDefaultInstance() to get.
If you need several instance, run Init() with different <name>. Use GetInstance(<name>) to get.

func IsForbiddenPort

func IsForbiddenPort(port int) bool

func ServeContent

func ServeContent(hs *EchoServer, w http.ResponseWriter, req *http.Request, name string, modtime time.Time, content io.ReadSeeker)

ServeContent replies to the request using the content in the provided ReadSeeker. The main benefit of ServeContent over io.Copy is that it handles Range requests properly, sets the MIME type, and handles If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since, and If-Range requests.

If the response's Content-Type header is not set, ServeContent first tries to deduce the type from name's file extension and, if that fails, falls back to reading the first block of the content and passing it to DetectContentType. The name is otherwise unused; in particular it can be empty and is never sent in the response.

If modtime is not the zero time or Unix epoch, ServeContent includes it in a Last-Modified header in the response. If the request includes an If-Modified-Since header, ServeContent uses modtime to decide whether the content needs to be sent at all.

The content's Seek method must work: ServeContent uses a seek to the end of the content to determine its size.

If the caller has set w's ETag header formatted per RFC 7232, section 2.3, ServeContent uses it to handle requests using If-Match, If-None-Match, or If-Range.

Note that *os.File implements the io.ReadSeeker interface.

func ServeFile

func ServeFile(hs *EchoServer, w http.ResponseWriter, r *http.Request, name string)

ServeFile replies to the http.Request with the contents of the named file or directory.

If the provided file or directory name is a relative path, it is interpreted relative to the current directory and may ascend to parent directories. If the provided name is constructed from user input, it should be sanitized before calling ServeFile.

As a precaution, ServeFile will reject http.Requests where r.URL.Path contains a ".." path element; this protects against callers who might unsafely use filepath.Join on r.URL.Path without sanitizing it and then use that filepath.Join result as the name argument.

As another special case, ServeFile redirects any http.Request where r.URL.Path ends in "/index.html" to the same path, without the final "index.html". To avoid such redirects either modify the path or use ServeContent.

Outside of those two special cases, ServeFile does not use r.URL.Path for selecting the file or directory to serve; only the file or directory provided in the name argument is used.

Types

type Config

type Config struct {
	Port            int
	Tls             bool
	Crt_path        string
	Key_path        string
	Html_dir        string
	Html_index_path string
}

http_port

type Dir

type Dir string

A Dir implements FileSystem using the native file system restricted to a specific directory tree.

While the FileSystem.Open method takes '/'-separated paths, a Dir's string value is a filename on the native file system, not a URL, so it is separated by filepath.Separator, which isn't necessarily '/'.

Note that Dir could expose sensitive files and directories. Dir will follow symlinks pointing out of the directory tree, which can be especially dangerous if serving from a directory in which users are able to create arbitrary symlinks. Dir will also allow access to files and directories starting with a period, which could expose sensitive directories like .git or sensitive files like .htpasswd. To exclude files with a leading period, remove the files/directories from the server or create a custom FileSystem implementation.

An empty Dir is treated as ".".

func (Dir) Open

func (d Dir) Open(name string) (File, error)

Open implements FileSystem using os.Open, opening files for reading rooted and relative to the directory d.

type EchoServer

type EchoServer struct {
	*echo.Echo
	PauseMoment     int64
	Logger          log.Logger
	Http_port       int
	Tls             bool
	Crt_path        string
	Key_path        string
	Html_dir        string
	Html_index_path string
	Cert            *tls.Certificate
}

func GetInstance

func GetInstance() *EchoServer

func GetInstance_

func GetInstance_(name string) *EchoServer

func (*EchoServer) CheckStarted

func (s *EchoServer) CheckStarted() bool

check the server is indeed up

func (*EchoServer) Close

func (s *EchoServer) Close()

func (*EchoServer) FileWithPause

func (hs *EchoServer) FileWithPause(c echo.Context, filePath string, header map[string][]string, ignoreHeaderMap map[string]struct{}) (err error)

func (*EchoServer) GetPauseMoment

func (hs *EchoServer) GetPauseMoment() int64

func (*EchoServer) ReloadCert

func (s *EchoServer) ReloadCert() error

func (*EchoServer) SetPauseSeconds

func (hs *EchoServer) SetPauseSeconds(secs int64)

func (*EchoServer) Start

func (s *EchoServer) Start() error

type File

type File interface {
	io.Closer
	io.Reader
	io.Seeker
	Readdir(count int) ([]os.FileInfo, error)
	Stat() (os.FileInfo, error)
}

A File is returned by a FileSystem's Open method and can be served by the FileServer implementation.

The methods should behave the same as those on an *os.File.

type FileSystem

type FileSystem interface {
	Open(name string) (File, error)
}

A FileSystem implements access to a collection of named files. The elements in a file path are separated by slash ('/', U+002F) characters, regardless of host operating system convention.

Jump to

Keyboard shortcuts

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