refactor: optimize header parsing and remove factory naming
- Remove factory naming - Use direct byte indexing instead of bytes.TrimRight - Extract parseStartLine and setRemainingHeaders helpers
This commit is contained in:
+5
-5
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user