8000 [feature request] CLI option to add custom response headers · Issue #99 · cortesi/devd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[feature request] CLI option to add custom response headers #99
Open
@warren-bank

Description

@warren-bank

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 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0