コード例 #1
0
ファイル: adapter.go プロジェクト: reedobrien/twister
func webRequestFromHTTPRequest(w http.ResponseWriter, r *http.Request) *web.Request {
	header := web.Header(r.Header)

	url := *r.URL
	if url.Host == "" {
		url.Host = r.Host
	}

	req, _ := web.NewRequest(
		r.RemoteAddr,
		r.Method,
		url.RequestURI(),
		web.ProtocolVersion(r.ProtoMajor, r.ProtoMinor),
		&url,
		header)

	req.Body = r.Body
	req.Responder = responder{w}
	req.ContentLength = int(r.ContentLength)
	if r.Form != nil {
		req.Param = web.Values(r.Form)
	}
	req.Env["twister.adapter.request"] = r
	return req
}
コード例 #2
0
ファイル: gae.go プロジェクト: rene-dev/twister
func webRequestFromHTTPRequest(w http.ResponseWriter, r *http.Request) *web.Request {
	header := web.Header(map[string][]string(r.Header))
	foo := header.Get("Cookie")

	if r.Referer != "" {
		header.Set(web.HeaderReferer, r.Referer)
	}
	if r.UserAgent != "" {
		header.Set(web.HeaderUserAgent, r.UserAgent)
	}

	req, _ := web.NewRequest(
		r.RemoteAddr,
		r.Method,
		r.URL,
		web.ProtocolVersion(r.ProtoMajor, r.ProtoMinor),
		header)

	req.Body = r.Body
	req.Responder = responder{w}
	req.ContentLength = int(r.ContentLength)
	if r.Form != nil {
		req.Param = web.Values(map[string][]string(r.Form))
	}

	for _, c := range r.Cookie {
		req.Cookie.Add(c.Name, c.Value)
	}

	req.Env["foo"] = foo

	return req
}