Browse Source

support attributes in session.Content

pull/1581/head
Darien Raymond 6 years ago
parent
commit
888494aac8
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
  1. 16
      common/session/session.go
  2. 13
      proxy/http/server.go

16
common/session/session.go

@ -66,4 +66,20 @@ type Content struct {
Protocol string
SniffingRequest SniffingRequest
attr map[string]interface{}
}
func (c *Content) SetAttribute(name string, value interface{}) {
if c.attr == nil {
c.attr = make(map[string]interface{})
}
c.attr[name] = value
}
func (c *Content) Attribute(name string) interface{} {
if c.attr == nil {
return nil
}
return c.attr[name]
}

13
proxy/http/server.go

@ -239,9 +239,18 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
request.Header.Set("User-Agent", "")
}
ctx = session.ContextWithContent(ctx, &session.Content{
content := &session.Content{
Protocol: "http/1.1",
})
}
content.SetAttribute(":method", request.Method)
content.SetAttribute(":path", request.URL.Path)
for key := range request.Header {
value := request.Header.Get(key)
content.SetAttribute(strings.ToLower(key), value)
}
ctx = session.ContextWithContent(ctx, content)
link, err := dispatcher.Dispatch(ctx, dest)
if err != nil {

Loading…
Cancel
Save