chore(restructure): reorganize project layout
- Reorganize internal packages and overall project structure - Update imports and wiring to match the new layout - Separate HTTP parsing and streaming from the server package - Separate middleware from the server package - Separate session registry from the session package - Move HTTP, HTTPS, and TCP servers to the transport package - Session package no longer starts the TCP server directly - Server package no longer starts HTTP/HTTPS servers on initialization - Forwarder no longer handles accepting TCP requests - Move session details to the types package - HTTP/HTTPS initialization is now the responsibility of main
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package header
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func NewResponse(headerData []byte) (ResponseHeader, error) {
|
||||
header := &responseHeader{
|
||||
startLine: nil,
|
||||
headers: make(map[string]string, 16),
|
||||
}
|
||||
|
||||
lineEnd := bytes.Index(headerData, []byte("\r\n"))
|
||||
if lineEnd == -1 {
|
||||
return nil, fmt.Errorf("invalid response: no CRLF found in start line")
|
||||
}
|
||||
|
||||
header.startLine = headerData[:lineEnd]
|
||||
remaining := headerData[lineEnd+2:]
|
||||
setRemainingHeaders(remaining, header)
|
||||
|
||||
return header, nil
|
||||
}
|
||||
|
||||
func (resp *responseHeader) Value(key string) string {
|
||||
return resp.headers[key]
|
||||
}
|
||||
|
||||
func (resp *responseHeader) Set(key string, value string) {
|
||||
resp.headers[key] = value
|
||||
}
|
||||
|
||||
func (resp *responseHeader) Remove(key string) {
|
||||
delete(resp.headers, key)
|
||||
}
|
||||
|
||||
func (resp *responseHeader) Finalize() []byte {
|
||||
return finalize(resp.startLine, resp.headers)
|
||||
}
|
||||
Reference in New Issue
Block a user