Skip to content

Commit

Permalink
feat: add response header
Browse files Browse the repository at this point in the history
Signed-off-by: 逆流而上 <[email protected]>
  • Loading branch information
DokiDoki1103 committed Feb 19, 2024
1 parent d755a58 commit 3736bbe
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/handler/gateway_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ func (g *GatewayAction) RuleConfig(req *apimodel.RuleConfigReq) error {
item.Value = "empty"
}
// filter same key
setheaders["resp-header-"+item.Key] = item.Value
responseHeaders["resp-header-"+item.Key] = item.Value
}
for k, v := range responseHeaders {
configs = append(configs, &model.GwRuleConfig{
Expand Down
1 change: 1 addition & 0 deletions gateway/annotations/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ func (a proxy) Parse(meta *metav1.ObjectMeta) (interface{}, error) {
}

// response header
config.ResponseHeaders = make(map[string]string)
responseHeaders, err := parser.GetStringAnnotationWithPrefix("resp-header-", meta)
if err != nil && !strings.Contains(err.Error(), "ingress rule without annotations") {
logrus.Debugf("get header annotation failure %s", err.Error())
Expand Down
10 changes: 5 additions & 5 deletions gateway/controller/openresty/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type OrService struct {
configManage *template.NginxConfigFileTemplete
}

//CreateOpenrestyService create openresty service
// CreateOpenrestyService create openresty service
func CreateOpenrestyService(config *option.Config, isShuttingDown *bool) *OrService {
gws := &OrService{
IsShuttingDown: isShuttingDown,
Expand Down Expand Up @@ -152,10 +152,10 @@ func (o *OrService) PersistConfig(conf *v1.Config) error {
o.configManage.WriteServer(*o.ocfg, "stream", "", l4srv...)

// reload nginx
if err := nginxcmd.Reload(); err != nil {
logrus.Errorf("Nginx reloads falure %s", err.Error())
return err
}
//if err := nginxcmd.Reload(); err != nil {
// logrus.Errorf("Nginx reloads falure %s", err.Error())
// return err
//}
logrus.Debug("Nginx reloads successfully.")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion hack/contrib/docker/gateway/nginxtmp/servers.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ server {
proxy_set_header {{$k}} {{$v}};
{{ end }}

# set response headers
# custom set response headers
{{ range $k1, $v1 := $loc.Proxy.ResponseHeaders }}
add_header {{$k1}} {{$v1}};
{{ end }}
Expand Down

0 comments on commit 3736bbe

Please sign in to comment.