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

[feature request] CLI option to add custom response headers #99

Open
warren-bank opened this issue Jan 14, 2019 · 1 comment
Open

[feature request] CLI option to add custom response headers #99

warren-bank opened this issue Jan 14, 2019 · 1 comment

Comments

@warren-bank
Copy link

warren-bank commented Jan 14, 2019

the following code is borrowed from this example..

I made a few minor changes, but I'm not familiar with the Go language.. so the syntax may be need some correction.

it could be applied to devd.go..

type HTTPHeaderValue http.Header

func (h HTTPHeaderValue) Set(value string) error {
  parts := strings.SplitN(value, ":", 2)
  if len(parts) != 2 {
    return fmt.Errorf("expected 'HEADER:VALUE' got '%s'", value)
  }
  (http.Header)(h).Add(parts[0], parts[1])
  return nil
}

func (h HTTPHeaderValue) String() string {
  return ""
}

func (h HTTPHeaderValue) IsCumulative() bool {
  return true
}

func HTTPHeader(s kingpin.Settings) (target *http.Header) {
  target = &http.Header{}
  s.SetValue((*HTTPHeaderValue)(target))
  return
}

hdrs := HTTPHeader(kingpin.Flag("header", "Add HTTP response header").Short('H').PlaceHolder("HEADER:VALUE"))

if *cors {
  hdrs.Set("Access-Control-Allow-Origin", "*")
}

the intention is to accept multiple CLI --header="name:value" options

ex:

devd --header="Strict-Transport-Security:max-age=0" --header="Cache-Control:max-age=0" --port=443 --all --tls .
@warren-bank
Copy link
Author

after-thought:

  • -H is already associated with a different option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant