SetRequestHeader

设置HTTP请求头的值,如果该值已存在,则覆盖。

Example

  1. package main
  2. import (
  3. "github.com/vicanso/elton"
  4. "github.com/vicanso/elton/middleware"
  5. )
  6. func main() {
  7. e := elton.New()
  8. e.Use(middleware.NewDefaultResponder())
  9. e.GET("/", func(c *elton.Context) (err error) {
  10. c.SetRequestHeader("User-Agent", "go-agent")
  11. c.Body = c.GetRequestHeader("User-Agent")
  12. return
  13. })
  14. err := e.ListenAndServe(":3000")
  15. if err != nil {
  16. panic(err)
  17. }
  18. }