Skip to content

Commit

Permalink
optimize http codebase quality
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhaoxx committed Feb 20, 2024
1 parent 6e4e511 commit 6352d0b
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 231 deletions.
2 changes: 1 addition & 1 deletion auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type AuthRet uint8

const PrefixAuth = "/auth"
const InternalAuthPath = 119

const (
AC AuthRet = 0 //accept
DE AuthRet = 1 //deny
Expand Down
4 changes: 2 additions & 2 deletions auth/policybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (l *policyBaseAuth) HandleProxy(ctx *http.HttpCtx) http.Ret {

}

func (mgr *policyBaseAuth) HandleHTTPInternal(ctx *http.HttpCtx, path string) http.Ret {
func (mgr *policyBaseAuth) HandleHTTPCgi(ctx *http.HttpCtx, path string) http.Ret {
cookie, _ := ctx.Req.Cookie(verfiyCookieKey)
var session *session
var user string
Expand Down Expand Up @@ -368,7 +368,7 @@ func (mgr *policyBaseAuth) HandleHTTPInternal(ctx *http.HttpCtx, path string) ht

var regexpforit = regexp2.MustCompile("^"+PrefixAuth+PrefixAuthPolicy+"/.*$", 0)

func (l *policyBaseAuth) PathsInternal() utils.GroupRegexp {
func (l *policyBaseAuth) Paths() utils.GroupRegexp {
return []*regexp2.Regexp{regexpforit}
}

Expand Down
8 changes: 6 additions & 2 deletions dns/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,17 @@ func (s *server) AddRecordWithIP(name string, ip string) error {
s.AddRecord(regexp2.MustCompile(Dnsname2Regexp(real_ptr), 0), dns.TypePTR, real_subdomain, 60)

return nil

}
func (s *server) SetDomain(domain string) *server {
s.domain = domain
return s
}

func NewServer(domain string) (ret *server) {
func NewServer() (ret *server) {
ret = &server{
records: []*record{},
filters: []*filter{},
domain: domain,
count: 0,
}
ret.bufferedLookupForFilters = utils.NewBufferedLookup(func(s string) interface{} {
Expand Down
30 changes: 30 additions & 0 deletions http/cgi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package http

import (
"strings"
)

const PrefixNg = "/ng-cgi"

func (mid *Midware) ngCgi(RequestCtx *HttpCtx) Ret {

path := strings.TrimPrefix(RequestCtx.Req.URL.Path, PrefixNg)

s := mid.bufferedLookupForCgi.Lookup(path).([]*CgiStruct)

if len(s) == 0 {
RequestCtx.Resp.ErrorPage(StatusNotFound, "The requested URL "+RequestCtx.Req.RequestURI+"("+path+")"+" was not found on this server.")
}

for _, t := range s {
switch t.CgiHandler(RequestCtx, path) {
case RequestEnd:
goto _break
case Continue:
continue
}
}

_break:
return RequestEnd
}
10 changes: 5 additions & 5 deletions http/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

func (h *Midware) ngForwardProxy(ctx *HttpCtx) Ret {
if h.proxychan != nil {
for _, v := range h.proxychan {
if h.currentProxy != nil {
for _, v := range h.currentProxy {
switch v(ctx) {
case RequestEnd:
return RequestEnd
Expand All @@ -25,7 +25,7 @@ func (h *Midware) ngForwardProxy(ctx *HttpCtx) Ret {
}

func (h *Midware) AddForwardProxiers(p ...ServiceHandler) {
h.proxychan = append(h.proxychan, p...)
h.currentProxy = append(h.currentProxy, p...)
}

func StdForwardProxy(ctx *HttpCtx) Ret {
Expand Down Expand Up @@ -152,10 +152,10 @@ func proxyh2(ctx context.Context, leftreader io.ReadCloser, leftwriter io.Writer
<-groupdone
}

const COPY_BUF = 128 * 1024
const copy_buf = 128 * 1024

func copyBody(wr io.Writer, body io.Reader) {
buf := make([]byte, COPY_BUF)
buf := make([]byte, copy_buf)
for {
bread, read_err := body.Read(buf)
var write_err error
Expand Down
6 changes: 0 additions & 6 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (c *HttpCtx) RegCloseHandle(f func(*HttpCtx)) {
var h2s = &http2.Server{}

type Ret bool
type ServiceHandler func(*HttpCtx) Ret

const (
RequestEnd Ret = false
Expand Down Expand Up @@ -140,11 +139,6 @@ func (h *Midware) head(rw http.ResponseWriter, r *http.Request, conn *tcp.Conn)
h.Process(ctx)
}

const (
Mainhost = iota + 100
Maindomain
)

type NgResponseWriter struct {
writer io.Writer
stdrw http.ResponseWriter
Expand Down
87 changes: 0 additions & 87 deletions http/internal.go

This file was deleted.

Loading

0 comments on commit 6352d0b

Please sign in to comment.