当前位置: 首页>>代码示例>>Golang>>正文


Golang FilterContext.Request方法代码示例

本文整理汇总了Golang中github.com/zalando/skipper/filters.FilterContext.Request方法的典型用法代码示例。如果您正苦于以下问题:Golang FilterContext.Request方法的具体用法?Golang FilterContext.Request怎么用?Golang FilterContext.Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/zalando/skipper/filters.FilterContext的用法示例。


在下文中一共展示了FilterContext.Request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ServeHTTP

// Creates a response from a handler and a request.
//
// It calls the handler's ServeHTTP method with an internal response
// writer that shares the status code, headers and the response body
// with the returned response. It blocks until the handler calls the
// response writer's WriteHeader, or starts writing the body, or
// returns. The written body is not buffered, but piped to the returned
// response's body.
//
// Example, a simple file server:
//
// 	var handler = http.StripPrefix(webRoot, http.FileServer(http.Dir(root)))
//
// 	func (f *myFilter) Request(ctx filters.FilterContext) {
// 		serve.ServeHTTP(ctx, handler)
// 	}
//
func ServeHTTP(ctx filters.FilterContext, h http.Handler) {
	rsp := &http.Response{Header: make(http.Header)}
	r, w := io.Pipe()
	d := &pipedResponse{
		response:   rsp,
		reader:     r,
		writer:     w,
		headerDone: make(chan struct{})}

	req := ctx.Request()
	go func() {
		h.ServeHTTP(d, req)
		select {
		case <-d.headerDone:
		default:
			d.WriteHeader(http.StatusOK)
		}

		w.CloseWithError(io.EOF)
	}()

	<-d.headerDone
	rsp.Body = d
	ctx.Serve(rsp)
}
开发者ID:zalando,项目名称:skipper,代码行数:42,代码来源:serve.go

示例2: 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()
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:33,代码来源:redirect.go

示例3: Request

// Strips the query parameters and optionally preserves them in the X-Query-Param-xyz headers.
func (f *stripQuery) Request(ctx filters.FilterContext) {
	r := ctx.Request()
	if r == nil {
		return
	}

	url := r.URL
	if url == nil {
		return
	}

	if !f.preserveAsHeader {
		url.RawQuery = ""
		return
	}

	q := url.Query()
	for k, vv := range q {
		for _, v := range vv {
			if r.Header == nil {
				r.Header = http.Header{}
			}
			r.Header.Add(fmt.Sprintf("X-Query-Param-%s", sanitize(k)), v)
		}
	}

	url.RawQuery = ""
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:29,代码来源:stripquery.go

示例4: getLocation

func getLocation(ctx filters.FilterContext, location *url.URL) string {
	r := ctx.Request()

	uc := *location
	u := &uc

	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
	}

	return u.String()
}
开发者ID:zalando,项目名称:skipper,代码行数:30,代码来源:redirect.go

示例5: Request

func (t *throttle) Request(ctx filters.FilterContext) {
	switch t.typ {
	case latency, bandwidth, chunks:
		return
	}

	req := ctx.Request()
	req.Body = t.goThrottle(req.Body, false)
}
开发者ID:zalando,项目名称:skipper,代码行数:9,代码来源:diag.go

示例6: Request

func (f *headerFilter) Request(ctx filters.FilterContext) {
	if f.typ != requestHeader {
		return
	}

	ctx.Request().Header.Add(f.key, f.value)
	if strings.ToLower(f.key) == "host" {
		ctx.SetOutgoingHost(f.value)
	}
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:10,代码来源:headerfilter.go

示例7: Request

func (f *headerFilter) Request(ctx filters.FilterContext) {
	if f.typ == requestHeader {
		req := ctx.Request()
		if strings.ToLower(f.key) == "host" {
			req.Host = f.value
		}

		req.Header.Add(f.key, f.value)
	}
}
开发者ID:LappleApple,项目名称:skipper,代码行数:10,代码来源:headerfilter.go

示例8: 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):]))
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:12,代码来源:static.go

示例9: Request

// Request is copied and then modified to adopt changes in new backend
func (r *tee) Request(fc filters.FilterContext) {
	copyOfRequest := cloneRequest(r, fc.Request())
	go func() {
		rsp, err := r.client.Do(&copyOfRequest)
		if err != nil {
			log.Warn("error while tee request", err)
		}
		if err == nil {
			defer rsp.Body.Close()
		}
	}()
}
开发者ID:zalando,项目名称:skipper,代码行数:13,代码来源:tee.go

示例10: Request

func (preserve filter) Request(ctx filters.FilterContext) {
	u, err := url.Parse(ctx.BackendUrl())
	if err != nil {
		log.Error("failed to parse backend host in preserveHost filter", err)
		return
	}

	if preserve && ctx.OutgoingHost() == u.Host {
		ctx.SetOutgoingHost(ctx.Request().Host)
	} else if !preserve && ctx.OutgoingHost() == ctx.Request().Host {
		ctx.SetOutgoingHost(u.Host)
	}
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:13,代码来源:preservehost.go

示例11: Request

// check basic auth
func (a *basic) Request(ctx filters.FilterContext) {
	username := a.authenticator.CheckAuth(ctx.Request())

	if username == "" {
		header := http.Header{}
		header.Set(ForceBasicAuthHeaderName, a.realmDefinition)

		ctx.Serve(&http.Response{
			StatusCode: http.StatusUnauthorized,
			Header:     header,
		})
	}
}
开发者ID:zalando,项目名称:skipper,代码行数:14,代码来源:basic.go

示例12: Response

func (c *compress) Response(ctx filters.FilterContext) {
	rsp := ctx.Response()

	if !canEncodeEntity(rsp, c.mime) {
		return
	}

	enc := acceptedEncoding(ctx.Request())
	if enc == "" {
		return
	}

	responseHeader(rsp, enc)
	responseBody(rsp, enc, c.level)
}
开发者ID:zalando,项目名称:skipper,代码行数:15,代码来源:compress.go

示例13: Request

func (f *flowId) Request(fc filters.FilterContext) {
	r := fc.Request()
	var flowId string

	if f.reuseExisting {
		flowId = r.Header.Get(HeaderName)
		if isValid(flowId) {
			return
		}
	}

	flowId, err := NewFlowId(f.flowIdLength)
	if err == nil {
		r.Header.Set(HeaderName, flowId)
	} else {
		log.Println(err)
	}
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:18,代码来源:filter.go

示例14: Request

func (f *headerFilter) Request(ctx filters.FilterContext) {
	switch f.typ {
	case setRequestHeader:
		ctx.Request().Header.Set(f.key, f.value)
		if strings.ToLower(f.key) == "host" {
			ctx.SetOutgoingHost(f.value)
		}
	case appendRequestHeader, depRequestHeader:
		ctx.Request().Header.Add(f.key, f.value)
		if strings.ToLower(f.key) == "host" {
			ctx.SetOutgoingHost(f.value)
		}
	case dropRequestHeader:
		ctx.Request().Header.Del(f.key)
	}
}
开发者ID:zalando,项目名称:skipper,代码行数:16,代码来源:headerfilter.go

示例15: Request

func (rc *requestCheck) Request(ctx filters.FilterContext) {
	if !rc.check(ctx.Request()) {
		ctx.Serve(&http.Response{StatusCode: http.StatusBadRequest})
	}
}
开发者ID:zalando,项目名称:skipper,代码行数:5,代码来源:diag_test.go


注:本文中的github.com/zalando/skipper/filters.FilterContext.Request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。