コード例 #1
0
ファイル: server.go プロジェクト: kr/spdy
// ServeConn serves incoming SPDY requests on c.
// Most people don't need this; they should use
// ListenAndServeTLS instead.
func (s *Server) ServeConn(c net.Conn) error {
	defer c.Close()
	fr := framing.NewFramer(c, c)
	sess := framing.Start(fr, true, func(st *framing.Stream) {
		s.serveStream(st, c)
	})
	return sess.Wait()
}
コード例 #2
0
ファイル: conn.go プロジェクト: kr/spdy
// RoundTrip implements interface http.RoundTripper.
func (c *Conn) RoundTrip(r *http.Request) (*http.Response, error) {
	c.once.Do(func() {
		fr := framing.NewFramer(c.Conn, c.Conn)
		c.s = framing.Start(fr, false, func(s *framing.Stream) {
			// TODO(kr): Make each stream available
			//           to its associated request.
			s.Reset(framing.RefusedStream)
		})
	})
	reqHeader, flag, err := RequestFramingHeader(r)
	body := r.Body
	r.Body = nil
	if err != nil {
		return nil, err
	}
	st, err := c.s.Open(reqHeader, flag)
	if err != nil {
		return nil, err
	}
	if body != nil {
		go func() {
			// TODO(kr): handle errors
			_, err := io.Copy(st, body)
			if err != nil {
				return
			}
			st.Close()
		}()
	}
	h := st.Header() // waits for SYN_REPLY
	resp, err := ReadResponse(h, nil, st, r)
	if err != nil {
		st.Reset(framing.ProtocolError)
		return nil, err
	}
	resp.Request = r
	return resp, nil
}