Skip to content

Commit

Permalink
coprocess: use metadata as map[string]string, enhance conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasinsaurralde authored and buger committed Jun 13, 2018
1 parent f106230 commit 0c6df69
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 90 deletions.
16 changes: 4 additions & 12 deletions coprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,6 @@ func (c *CoProcessor) ObjectFromRequest(r *http.Request) *coprocess.Object {
if c.HookType != coprocess.HookType_Pre && c.HookType != coprocess.HookType_CustomKeyCheck {
if session := ctxGetSession(r); session != nil {
object.Session = ProtoSessionState(session)
// If the session contains metadata, add items to the object's metadata map:
if len(session.MetaData) > 0 {
object.Metadata = make(map[string]string)
for k, v := range session.MetaData {
object.Metadata[k] = v.(string)
}
}
}
}

Expand Down Expand Up @@ -278,7 +271,10 @@ func (m *CoProcessMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Requ

coProcessor.ObjectPostProcess(returnObject, r)

token := returnObject.Metadata["token"]
var token string
if returnObject.Session != nil {
token = returnObject.Session.Metadata["token"]
}

// The CP middleware indicates this is a bad auth:
if returnObject.Request.ReturnOverrides.ResponseCode > 400 {
Expand Down Expand Up @@ -320,10 +316,6 @@ func (m *CoProcessMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Requ

returnedSession := TykSessionState(returnObject.Session)

// If the returned object contains metadata, add them to the session:
for k, v := range returnObject.Metadata {
returnedSession.MetaData[k] = string(v)
}
if extractor == nil {
sessionLifetime := returnedSession.Lifetime(m.Spec.SessionLifetime)
// This API is not using the ID extractor, but we've got a session:
Expand Down
67 changes: 58 additions & 9 deletions coprocess/bindings/python/coprocess_session_state_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coprocess/bindings/ruby/coprocess_session_state_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0c6df69

Please sign in to comment.