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 }
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 }
func (c *conn) prepare() (err os.Error) { method, rawURL, version, err := parseRequestLine(c.br) if err != nil { return err } header, err := parseHeader(c.br) if err != nil { return err } url, err := http.ParseURL(rawURL) if err != nil { return err } if url.Host == "" { url.Host = header.GetDef(web.HeaderHost, "") if url.Host == "" { url.Host = c.serverName } } if c.secure { url.Scheme = "https" } else { url.Scheme = "http" } req, err := web.NewRequest(c.netConn.RemoteAddr().String(), method, url, version, header) if err != nil { return } c.req = req c.requestAvail = req.ContentLength if c.requestAvail < 0 { c.requestAvail = 0 } if s, found := req.Header.Get(web.HeaderExpect); found { c.write100Continue = strings.ToLower(s) == "100-continue" } connection := strings.ToLower(req.Header.GetDef(web.HeaderConnection, "")) if version >= web.ProtocolVersion(1, 1) { c.closeAfterResponse = connection == "close" } else if version == web.ProtocolVersion(1, 0) && req.ContentLength >= 0 { c.closeAfterResponse = connection != "keep-alive" } else { c.closeAfterResponse = true } req.Responder = c req.Body = requestReader{c} return nil }
func (t *transaction) prepare() (err error) { method, requestURI, version, err := readRequestLine(t.br) if err != nil { return err } header := web.Header{} err = header.ParseHttpHeader(t.br) if err != nil { return err } u, err := url.ParseRequestURI(requestURI) if err != nil { return err } if u.Host == "" { u.Host = header.Get(web.HeaderHost) if u.Host == "" { u.Host = t.server.DefaultHost } } if t.server.Secure { u.Scheme = "https" } else { u.Scheme = "http" } req, err := web.NewRequest(t.conn.RemoteAddr().String(), method, requestURI, version, u, header) if err != nil { return } t.req = req if s := req.Header.Get(web.HeaderExpect); s != "" { t.write100Continue = strings.ToLower(s) == "100-continue" } connection := strings.ToLower(req.Header.Get(web.HeaderConnection)) if version >= web.ProtocolVersion(1, 1) { t.closeAfterResponse = connection == "close" } else if version == web.ProtocolVersion(1, 0) && req.ContentLength >= 0 { t.closeAfterResponse = connection != "keep-alive" } else { t.closeAfterResponse = true } req.Responder = t te := header.GetList(web.HeaderTransferEncoding) chunked := len(te) > 0 && te[0] == "chunked" switch { case req.Method == "GET" || req.Method == "HEAD": req.Body = identityReader{t} t.requestConsumed = true case chunked: req.Body = chunkedReader{t} case req.ContentLength >= 0: req.Body = identityReader{t} t.requestAvail = req.ContentLength t.requestConsumed = req.ContentLength == 0 default: req.Body = identityReader{t} t.closeAfterResponse = true } return nil }