本文整理汇总了Golang中github.com/zalando/skipper/filters.FilterContext.ResponseWriter方法的典型用法代码示例。如果您正苦于以下问题:Golang FilterContext.ResponseWriter方法的具体用法?Golang FilterContext.ResponseWriter怎么用?Golang FilterContext.ResponseWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/zalando/skipper/filters.FilterContext
的用法示例。
在下文中一共展示了FilterContext.ResponseWriter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Response
// Sets the status code and the location header of the response. Marks the
// request served.
func (f *redirect) Response(ctx filters.FilterContext) {
r := ctx.Request()
w := ctx.ResponseWriter()
u := f.copyOfLocation()
if u.Scheme == "" {
if r.URL.Scheme != "" {
u.Scheme = r.URL.Scheme
} else {
u.Scheme = "https"
}
}
u.User = r.URL.User
if u.Host == "" {
u.Host = getRequestHost(r)
}
if u.Path == "" {
u.Path = r.URL.Path
}
if u.RawQuery == "" {
u.RawQuery = r.URL.RawQuery
}
w.Header().Set("Location", u.String())
w.WriteHeader(f.code)
ctx.MarkServed()
}
示例2: Response
// Serves content from the file system and marks the request served.
func (f *static) Response(ctx filters.FilterContext) {
r := ctx.Request()
p := r.URL.Path
if len(p) < len(f.webRoot) {
return
}
ctx.MarkServed()
http.ServeFile(ctx.ResponseWriter(), ctx.Request(), path.Join(f.root, p[len(f.webRoot):]))
}
示例3: Response
// Sets the status code and the location header of the response. Marks the
// request served.
func (f *redirect) Response(ctx filters.FilterContext) {
if !f.deprecated {
return
}
u := getLocation(ctx, f.location)
w := ctx.ResponseWriter()
w.Header().Set("Location", u)
w.WriteHeader(f.code)
ctx.MarkServed()
}