Files
drip/internal/shared/httputil/detection.go
zhiqing 307cf8e6cc feat: Add Bearer Token authentication support and optimize code structure
- Add Bearer Token authentication, supporting tunnel access control via the --auth-bearer parameter
- Refactor large modules into smaller, more focused components to improve code maintainability
- Update dependency versions, including golang.org/x/crypto, golang.org/x/net, etc.
- Add SilenceUsage and SilenceErrors configuration for all CLI commands
- Modify connector configuration structure to support the new authentication method
- Update recent change log in README with new feature descriptions

BREAKING CHANGE: Authentication via Bearer Token is now supported, requiring the new --auth-bearer parameter
2026-01-29 14:40:53 +08:00

40 lines
902 B
Go

package httputil
import "strings"
// HTTPMethods contains common HTTP method prefixes for protocol detection.
var HTTPMethods = []string{
"GET ", "POST", "PUT ", "DELE", "HEAD", "OPTI", "PATC", "CONN", "TRAC",
}
// IsHTTPRequest checks if the given bytes represent the start of an HTTP request.
// It checks for common HTTP method prefixes.
func IsHTTPRequest(data []byte) bool {
if len(data) < 4 {
return false
}
dataStr := string(data[:4])
for _, method := range HTTPMethods {
if strings.HasPrefix(dataStr, method) {
return true
}
}
return false
}
// DetectHTTPMethod returns the HTTP method if the data starts with one, or empty string.
func DetectHTTPMethod(data []byte) string {
if len(data) < 4 {
return ""
}
dataStr := string(data)
for _, method := range HTTPMethods {
if strings.HasPrefix(dataStr, method) {
return strings.TrimSpace(method)
}
}
return ""
}