You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having a issue with some middleware ... i'm not sure if it's a bug, or more likely the way i'm using it ... The service consumes the json payload, perform some check, aborts the context if required otherwise the proxy middleware forwards the require on. The proxy works fine for the urls not hitting the handler, but when it hits the handler, even with the context not abort the proxy middleware handler is never called, it just returns a 200 but is never forwarded .... Any help would be much appreciated!
Gin Setup
// step: create the gin routerrouter:=gin.Default()
// step: handle operations related to replication controllers]
{
replicationEndpoint:="/api/v1/namespaces/:namespace/replicationcontrollers"router.POST(replicationEndpoint, service.handleReplicationController)
}
router.Use(service.proxyHandler())
Handler
func (r*Service) handleReplicationController(cx*gin.Context) {
READPAYLOAD, PERFORMSOMECHECKANDSETTHEBODYTOORIGINALCONTENT// check the content is still theredump, err:=httputil.DumpRequest(cx.Request, true)
iferr==nil {
glog.V(10).Infof("%s", dump)
}
glog.V(10).Infof("continuing the chain, is aborted: %t", cx.IsAborted())
}
Decode Input
// decode the payload and set the request body back to the original contentfunc (r*Service) decodeInput(req*http.Request, datainterface{}) (string, error) {
// step: read in the content payloadcontent, err:=ioutil.ReadAll(req.Body)
iferr!=nil {
glog.Errorf("unable to read in the content, error: %s", err)
return"", err
}
deferfunc() {
// we need to set the content backreq.Body=ioutil.NopCloser(bytes.NewReader(content))
}()
rdr:=strings.NewReader(string(content))
// step: decode the jsonerr=json.NewDecoder(rdr).Decode(data)
iferr!=nil {
glog.Errorf("unable to decode the request body, error: %s", err)
return"", err
}
returnstring(content), nil
}
Proxy Middleware
func (r*Service) proxyHandler() gin.HandlerFunc {
returnfunc(cx*gin.Context) {
fmt.Println("PROXYING ON")
// step: does the connection need upgrading?ifcx.Request.Header.Get("Upgrade") !="" {
iferr:=r.hijackRequest(cx); err!=nil {
glog.Errorf("unable to upgrade the connetcion, %s", err)
}
return
}
// step: pass into the reverse proxyr.proxy.ServeHTTP(cx.Writer, cx.Request)
}
}
Output
PROXYING ON
[GIN] 2015/11/16 - 12:07:10 | 200 | 130.368449ms | 127.0.0.1 | GET /api
I1116 12:07:10.975621 20514 handlers.go:57] continuing the chain, is aborted: false
[GIN] 2015/11/16 - 12:07:10 | 200 | 19.52µs | 127.0.0.1:40498 | POST /api/v1/namespaces/default/replicationcontrollers
The text was updated successfully, but these errors were encountered:
I'm having a issue with some middleware ... i'm not sure if it's a bug, or more likely the way i'm using it ... The service consumes the json payload, perform some check, aborts the context if required otherwise the proxy middleware forwards the require on. The proxy works fine for the urls not hitting the handler, but when it hits the handler, even with the context not abort the proxy middleware handler is never called, it just returns a 200 but is never forwarded .... Any help would be much appreciated!
Gin Setup
Handler
Decode Input
Proxy Middleware
Output
The text was updated successfully, but these errors were encountered: