MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / AddCorsOption

Method AddCorsOption

agent/utils/nginx/components/location.go:352–380  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

350}
351
352func (l *Location) AddCorsOption() {
353 l.RemoveCorsOption()
354 newDir := &Directive{
355 Name: "if",
356 Parameters: []string{"(", "$request_method", "=", "'OPTIONS'", ")"},
357 Block: &Block{},
358 }
359 block := &Block{}
360 block.AppendDirectives(&Directive{
361 Name: "add_header",
362 Parameters: []string{"Access-Control-Max-Age", "1728000"},
363 })
364 block.AppendDirectives(&Directive{
365 Name: "add_header",
366 Parameters: []string{"Content-Type", "'text/plain;charset=UTF-8'"},
367 })
368 block.AppendDirectives(&Directive{
369 Name: "add_header",
370 Parameters: []string{"Content-Length", "0"},
371 })
372 block.AppendDirectives(&Directive{
373 Name: "return",
374 Parameters: []string{"204"},
375 })
376 newDir.Block = block
377 directives := l.GetDirectives()
378 directives = append(directives, newDir)
379 l.Directives = directives
380}
381
382func (l *Location) RemoveCorsOption() {
383 l.RemoveDirectiveByFullParams("if", []string{"(", "$request_method", "=", "'OPTIONS'", ")"})

Callers 1

OperateProxyMethod · 0.95

Calls 3

RemoveCorsOptionMethod · 0.95
AppendDirectivesMethod · 0.95
GetDirectivesMethod · 0.95

Tested by

no test coverage detected