import path
This commit is contained in:
24
http/http.go
24
http/http.go
@@ -3,12 +3,12 @@ package http
|
||||
import (
|
||||
"strings"
|
||||
|
||||
csm "git.loafle.net/commons/service_matcher-go"
|
||||
osm "git.loafle.net/overflow/service_matcher-go"
|
||||
)
|
||||
|
||||
type HTTPMatcher struct {
|
||||
csm.Matchers
|
||||
meta csm.Metadata
|
||||
osm.Matchers
|
||||
meta osm.Metadata
|
||||
}
|
||||
|
||||
func (h *HTTPMatcher) Key() string {
|
||||
@@ -23,7 +23,7 @@ func (h *HTTPMatcher) Name() string {
|
||||
return name
|
||||
}
|
||||
|
||||
func (h *HTTPMatcher) Meta() csm.Metadata {
|
||||
func (h *HTTPMatcher) Meta() osm.Metadata {
|
||||
return h.meta
|
||||
}
|
||||
|
||||
@@ -35,27 +35,27 @@ func (h *HTTPMatcher) HasResponse(index int) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (h *HTTPMatcher) IsError(info csm.MatchInfo, index int, packet *csm.Packet) bool {
|
||||
func (h *HTTPMatcher) IsError(info osm.MatchInfo, index int, packet *osm.Packet) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (h *HTTPMatcher) Match(info csm.MatchInfo, index int, packet *csm.Packet) error {
|
||||
func (h *HTTPMatcher) Match(info osm.MatchInfo, index int, packet *osm.Packet) error {
|
||||
|
||||
if packet == nil || packet.Buffer == nil || packet.Len == 0 {
|
||||
return csm.NoPacketReceivedError()
|
||||
return osm.NoPacketReceivedError()
|
||||
}
|
||||
|
||||
str := string(packet.Buffer)
|
||||
elems := strings.Split(str, "\r\n")
|
||||
|
||||
if len(elems) <= 0 || 9 > len(elems[0]) {
|
||||
return csm.NotMatchedError()
|
||||
return osm.NotMatchedError()
|
||||
}
|
||||
|
||||
protocol := (elems[0])[:8]
|
||||
|
||||
if !strings.HasPrefix(protocol, "HTTP/") {
|
||||
return csm.NotMatchedError()
|
||||
return osm.NotMatchedError()
|
||||
}
|
||||
|
||||
serverName := ""
|
||||
@@ -76,16 +76,16 @@ func (h *HTTPMatcher) Match(info csm.MatchInfo, index int, packet *csm.Packet) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewMatcher() csm.Matcher {
|
||||
func NewMatcher() osm.Matcher {
|
||||
|
||||
m := &HTTPMatcher{}
|
||||
m.meta = csm.NewMetadata()
|
||||
m.meta = osm.NewMetadata()
|
||||
|
||||
reqStr := "GET / HTTP/1.1\r\n\r\n"
|
||||
byte := make([]byte, len(reqStr))
|
||||
copy(byte[:], reqStr)
|
||||
|
||||
m.AddPacket(csm.NewPacket(byte, len(reqStr)))
|
||||
m.AddPacket(osm.NewPacket(byte, len(reqStr)))
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
csm "git.loafle.net/commons/service_matcher-go"
|
||||
osm "git.loafle.net/overflow/service_matcher-go"
|
||||
)
|
||||
|
||||
func TestHTTP(t *testing.T) {
|
||||
@@ -26,7 +26,7 @@ func TestHTTP(t *testing.T) {
|
||||
}
|
||||
bytes := make([]byte, 1024)
|
||||
n, _ := conn.Read(bytes)
|
||||
p := csm.NewPacket(bytes, n)
|
||||
p := osm.NewPacket(bytes, n)
|
||||
|
||||
if err := m.Match(nil, i, p); err != nil {
|
||||
t.Error(err)
|
||||
@@ -65,7 +65,7 @@ func TestHTTPS(t *testing.T) {
|
||||
}
|
||||
bytes := make([]byte, 1024)
|
||||
n, _ := conn.Read(bytes)
|
||||
p := csm.NewPacket(bytes, n)
|
||||
p := osm.NewPacket(bytes, n)
|
||||
|
||||
if err := m.Match(nil, i, p); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user