Request & Response Modification service extension (Legacy)
Request & Response Modification service extension (Legacy)
ℹ️
This topic refers to legacy configuration syntax. App gateways are now defined as Proxy apps.
Certain situations require the ability to modify every request and response that flows through the AppGateway’s proxy. An example of this is setting an HTTP request header that contains a dynamic value, or changing the response code for a given resource.
In most Orchestration scenarios, modification of every request or response is unnecessary and can impact performance. These service extensions should be used only when necessary.
ModifyRequestSE
This Service Extension can be used to modify every request that passes through the AppGateway’s proxy.
appgateways:
- name: example
# ...
modifyRequestSE:
funcName: ModifyRequest
file: /etc/maverics/extensions/modifyRequest.go
/etc/maverics/extensions/modifyRequest.go
package main
import (
"net/http"
"time"
"maverics/app"
"maverics/log"
)
func ModifyRequest(ag *app.AppGateway, req *http.Request) {
log.Info("msg", "setting header on request")
req.Header.Set("X-Req-Time", time.Now().String())
}
ModifyResponseSE
This Service Extension can be used to modify every response that passes through the AppGateway’s proxy.
appgateways:
- name: example
# ...
modifyResponseSE:
funcName: ModifyResponse
file: /etc/maverics/extensions/modifyResponse.go
/etc/maverics/extensions/modifyResponse.go
package main
import (
"net/http"
"maverics/app"
"maverics/log"
)
func ModifyResponse(ag *app.AppGateway, resp *http.Response) {
if resp.Request.URL.Path != "/special/path/" {
return
}
log.Info("msg", "setting status code for '/special/path/' resource")
resp.StatusCode = http.StatusOK
}