Skip to content

Commit

Permalink
support attributes in session.Content
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Feb 28, 2019
1 parent 39835e8 commit 888494a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
16 changes: 16 additions & 0 deletions common/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 11 additions & 2 deletions proxy/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 888494a

Please sign in to comment.