mirror of
https://github.com/lkmio/lkm.git
synced 2025-09-26 19:21:14 +08:00
统一sourceid格式
This commit is contained in:
@@ -70,9 +70,14 @@ func (h handler) Process(session *session, method string, url_ *url.URL, headers
|
||||
return fmt.Errorf("please establish a session first")
|
||||
}
|
||||
|
||||
var err error
|
||||
split := strings.Split(url_.Path, "/")
|
||||
source := split[len(split)-1]
|
||||
source := strings.TrimSpace(url_.Path)
|
||||
if strings.HasPrefix(source, "/") {
|
||||
source = source[1:]
|
||||
}
|
||||
|
||||
if len(strings.TrimSpace(source)) == 0 {
|
||||
return fmt.Errorf("the request source cannot be empty")
|
||||
}
|
||||
|
||||
//反射调用各个处理函数
|
||||
results := m.Call([]reflect.Value{
|
||||
@@ -80,7 +85,7 @@ func (h handler) Process(session *session, method string, url_ *url.URL, headers
|
||||
reflect.ValueOf(Request{session, source, method, url_, headers}),
|
||||
})
|
||||
|
||||
err, _ = results[2].Interface().(error)
|
||||
err, _ := results[2].Interface().(error)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -97,7 +97,7 @@ func parseMessage(data []byte) (string, *url.URL, textproto.MIMEHeader, error) {
|
||||
line, err := tp.ReadLine()
|
||||
split := strings.Split(line, " ")
|
||||
if len(split) < 3 {
|
||||
panic(fmt.Errorf("unknow response line of response:%s", line))
|
||||
panic(fmt.Errorf("wrong request line %s", line))
|
||||
}
|
||||
|
||||
method := strings.ToUpper(split[0])
|
||||
@@ -109,6 +109,15 @@ func parseMessage(data []byte) (string, *url.URL, textproto.MIMEHeader, error) {
|
||||
return "", nil, nil, err
|
||||
}
|
||||
|
||||
path := strings.TrimSpace(url_.Path)
|
||||
if strings.HasPrefix(path, "/") {
|
||||
path = path[1:]
|
||||
}
|
||||
|
||||
if len(strings.TrimSpace(path)) == 0 {
|
||||
return "", nil, nil, fmt.Errorf("the request source cannot be empty")
|
||||
}
|
||||
|
||||
header, err := tp.ReadMIMEHeader()
|
||||
if err != nil {
|
||||
return "", nil, nil, err
|
||||
|
Reference in New Issue
Block a user