refactor: optimize header parsing and remove factory naming
Docker Build and Push / build-and-push-tags (push) Has been skipped
Docker Build and Push / build-and-push-branches (push) Successful in 11m20s

- Remove factory naming
- Use direct byte indexing instead of bytes.TrimRight
- Extract parseStartLine and setRemainingHeaders helpers
This commit is contained in:
2026-01-20 19:07:47 +07:00
parent aa1a465178
commit e3ead4d52f
4 changed files with 135 additions and 154 deletions
+5 -5
View File
@@ -112,7 +112,7 @@ func (hs *httpServer) handler(conn net.Conn, isTLS bool) {
defer hs.closeConnection(conn)
dstReader := bufio.NewReader(conn)
reqhf, err := NewRequestHeaderFactory(dstReader)
reqhf, err := NewRequestHeader(dstReader)
if err != nil {
log.Printf("Error creating request header: %v", err)
return
@@ -150,8 +150,8 @@ func (hs *httpServer) closeConnection(conn net.Conn) {
}
}
func (hs *httpServer) extractSlug(reqhf RequestHeaderManager) (string, error) {
host := strings.Split(reqhf.Get("Host"), ".")
func (hs *httpServer) extractSlug(reqhf RequestHeader) (string, error) {
host := strings.Split(reqhf.Value("Host"), ".")
if len(host) < 1 {
return "", errors.New("invalid host")
}
@@ -193,7 +193,7 @@ func (hs *httpServer) getSession(slug string) (session.Session, error) {
return sshSession, nil
}
func (hs *httpServer) forwardRequest(hw HTTPWriter, initialRequest RequestHeaderManager, sshSession session.Session) {
func (hs *httpServer) forwardRequest(hw HTTPWriter, initialRequest RequestHeader, sshSession session.Session) {
channel, err := hs.openForwardedChannel(hw, sshSession)
if err != nil {
log.Printf("Failed to establish channel: %v", err)
@@ -260,7 +260,7 @@ func (hs *httpServer) setupMiddlewares(hw HTTPWriter) {
hw.UseRequestMiddleware(forwardedForMiddleware)
}
func (hs *httpServer) sendInitialRequest(hw HTTPWriter, initialRequest RequestHeaderManager, channel ssh.Channel) error {
func (hs *httpServer) sendInitialRequest(hw HTTPWriter, initialRequest RequestHeader, channel ssh.Channel) error {
hw.SetRequestHeader(initialRequest)
if err := hw.ApplyRequestMiddlewares(initialRequest); err != nil {