Exemple #1
0
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
}
Exemple #2
0
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
}
Exemple #3
0
// SignParam adds an OAuth signature to param.
func (c *Client) SignParam(credentials *Credentials, method, urlStr string, param map[string][]string) {
	p := web.Values(param)
	p.Set("oauth_consumer_key", c.Credentials.Token)
	p.Set("oauth_signature_method", "HMAC-SHA1")
	p.Set("oauth_timestamp", strconv.Itoa64(time.Seconds()))
	p.Set("oauth_nonce", nonce())
	p.Set("oauth_version", "1.0")
	if c.Scope != "" {
		p.Set("scope", c.Scope)
	}
	if credentials != nil {
		p.Set("oauth_token", credentials.Token)
	}
	p.Set("oauth_signature", signature(&c.Credentials, credentials, method, urlStr, param))
}