Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging to release-4-lts: [TT-7127] Fix goplugin invalid memory address or nil pointer dereference (#5589) #5594

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions gateway/mw_go_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,16 @@ func (m *GoPluginMiddleware) goPluginFromRequest(r *http.Request) (*GoPluginMidd
return perPathPerMethodGoPlugin.(*GoPluginMiddleware), found
}
func (m *GoPluginMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Request, conf interface{}) (err error, respCode int) {
// if a Go plugin is found for this path, override the base handler and logger:
logger := m.logger
handler := m.handler
successHandler := m.successHandler

if !m.APILevel {
// if a Go plugin is found for this path, override the base handler and logger
if pluginMw, found := m.goPluginFromRequest(r); found {
logger = pluginMw.logger
handler = pluginMw.handler
successHandler = &SuccessHandler{BaseMiddleware: m.BaseMiddleware}
} else {
return nil, http.StatusOK // next middleware
}
Expand Down Expand Up @@ -226,7 +229,7 @@ func (m *GoPluginMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Reque
m.logger.WithError(err).Error("Failed to process request with Go-plugin middleware func")
default:
// record 2XX to analytics
m.successHandler.RecordHit(r, Latency{Total: int64(ms)}, rw.statusCodeSent, rw.getHttpResponse(r))
successHandler.RecordHit(r, Latency{Total: int64(ms)}, rw.statusCodeSent, rw.getHttpResponse(r))

// no need to continue passing this request down to reverse proxy
respCode = mwStatusRespond
Expand Down
Loading