當前位置: 首頁>>代碼示例>>Golang>>正文


Golang http.ReadResponse函數代碼示例

本文整理匯總了Golang中http.ReadResponse函數的典型用法代碼示例。如果您正苦於以下問題:Golang ReadResponse函數的具體用法?Golang ReadResponse怎麽用?Golang ReadResponse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ReadResponse函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ReadFrom

func ReadFrom(conn net.Conn, method string) (resp *http.Response, e os.Error) {
	// Read from and proccess the connection
	req := new(http.Request)
	req.Method = method

	reader := bufio.NewReader(conn)
	resp, e = http.ReadResponse(reader, req)
	if e != nil {
		fmt.Println("Error reading response:", e)
	}
	return
}
開發者ID:Epictetus,項目名稱:wfdr,代碼行數:12,代碼來源:main.go

示例2: Execute

// execute a request; date it, sign it, send it
func (bucket *Bucket) Execute(req *http.Request) (resp *http.Response, err os.Error) {
	// time stamp it
	date := time.LocalTime().Format(time.RFC1123)
	req.Header["Date"] = date

	// sign the request
	bucket.Sign(req)

	// open a connection
	conn, err := net.Dial("tcp", "", req.URL.Host+":"+req.URL.Scheme)
	if err != nil {
		return nil, err
	}

	// send the request
	req.Write(conn)

	// now read the response
	reader := bufio.NewReader(conn)
	resp, err = http.ReadResponse(reader, req.Method)
	if err != nil {
		return nil, err
	}

	return
}
開發者ID:sstephens,項目名稱:sstephens1,代碼行數:27,代碼來源:bucket.go

示例3: send

func send(req *http.Request) (resp *http.Response, err os.Error) {
	addr := req.URL.Host
	if !hasPort(addr) {
		addr += ":http"
	}
	conn, err := net.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}

	err = req.Write(conn)
	if err != nil {
		conn.Close()
		return nil, err
	}

	reader := bufio.NewReader(conn)
	resp, err = http.ReadResponse(reader, req.Method)
	if err != nil {
		conn.Close()
		return nil, err
	}

	r := io.Reader(reader)
	if n := resp.ContentLength; n != -1 {
		r = io.LimitReader(r, n)
	}
	resp.Body = readClose{r, conn}

	return
}
開發者ID:rene-dev,項目名稱:go-twitter,代碼行數:31,代碼來源:http_auth.go

示例4: send

func send(req *http.Request) (resp *http.Response, err os.Error) {
	addr := req.URL.Host
	if !hasPort(addr) {
		addr += ":http"
	}
	conn, err := net.Dial("tcp", "", addr)
	if err != nil {
		return nil, err
	}

	err = req.Write(conn)
	if err != nil {
		conn.Close()
		return nil, err
	}

	reader := bufio.NewReader(conn)
	resp, err = http.ReadResponse(reader, "GET")
	if err != nil {
		conn.Close()
		return nil, err
	}

	r := io.Reader(reader)
	if v := resp.GetHeader("Content-Length"); v != "" {
		n, err := strconv.Atoi64(v)
		if err != nil {
			//			return nil, &badStringError{"invalid Content-Length", v}
		}
		r = io.LimitReader(r, n)
	}
	resp.Body = readClose{r, conn}

	return
}
開發者ID:zlu,項目名稱:tropo-tutorial-go,代碼行數:35,代碼來源:new.go

示例5: draft75handshake

/*
Handhake described in (soon obsolete)
draft-hixie-thewebsocket-protocol-75.
*/
func draft75handshake(resourceName, host, origin, location, protocol string, br *bufio.Reader, bw *bufio.Writer) (err os.Error) {
	bw.WriteString("GET " + resourceName + " HTTP/1.1\r\n")
	bw.WriteString("Upgrade: WebSocket\r\n")
	bw.WriteString("Connection: Upgrade\r\n")
	bw.WriteString("Host: " + host + "\r\n")
	bw.WriteString("Origin: " + origin + "\r\n")
	if protocol != "" {
		bw.WriteString("WebSocket-Protocol: " + protocol + "\r\n")
	}
	bw.WriteString("\r\n")
	bw.Flush()
	resp, err := http.ReadResponse(br, "GET")
	if err != nil {
		return
	}
	if resp.Status != "101 Web Socket Protocol Handshake" {
		return ErrBadStatus
	}
	if resp.Header["Upgrade"] != "WebSocket" ||
		resp.Header["Connection"] != "Upgrade" {
		return ErrBadUpgrade
	}
	if resp.Header["Websocket-Origin"] != origin {
		return ErrBadWebSocketOrigin
	}
	if resp.Header["Websocket-Location"] != location {
		return ErrBadWebSocketLocation
	}
	if protocol != "" && resp.Header["Websocket-Protocol"] != protocol {
		return ErrBadWebSocketProtocol
	}
	return
}
開發者ID:GNA-SERVICES-INC,項目名稱:MoNGate,代碼行數:37,代碼來源:client.go

示例6: pipeRequestResponse

func pipeRequestResponse(server, client net.Conn) os.Error {

	// Read request from wire
	req, err := http.ReadRequest(bufio.NewReader(client))
	if err != nil {
		return err
	}

	rawReq, err := http.DumpRequest(req, true)
	if err != nil {
		return err
	}

	// forward it on
	server.Write(rawReq)

	// Read response from wire
	resp, err := http.ReadResponse(bufio.NewReader(server), req)
	if err != nil {
		return err
	}

	rawResp, err := http.DumpResponse(resp, true)
	if err != nil {
		return err
	}

	log.Printf("%s %s [%s]", req.Method, req.RawURL, resp.Status)

	// forward it on
	client.Write(rawResp)

	return nil
}
開發者ID:tobi,項目名稱:tinny,代碼行數:34,代碼來源:main.go

示例7: GetFile

func (bucket *Bucket) GetFile(file *os.FileInfo) (err os.Error) {
	url, e := http.ParseURL(bucket.Url + "/" + file.Name)
	if e != nil {
		return err
	}
	req := &http.Request{Method: "GET", RawURL: bucket.Url + "/" + file.Name, URL: url, Header: make(map[string]string)}
	date := time.LocalTime().Format(time.RFC1123)
	req.Header["Date"] = date
	bucket.sign(req)
	//req.Write(os.Stdout)

	conn, err := net.Dial("tcp", "", req.URL.Host+":"+req.URL.Scheme)
	if err != nil {
		return err
	}
	req.Write(conn)
	reader := bufio.NewReader(conn)
	resp, _ := http.ReadResponse(reader, req.Method)
	//resp.Write(os.Stdout)
	filename := strings.TrimLeft(url.Path, "/")
	path := strings.SplitAfter(filename, "/", -1)
	//pid := os.GetPid()

	var b []byte
	b, err = ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	mode := (file.Mode & 0777)
	fmt.Printf("0%o\n", mode)
	//var dirmode uint32
	//dirmode = (syscall.S_IFDIR^0666)&0777
	resp.Body.Close()

	//create file or dir
	for i := 0; i < len(path); i++ {
		f := i + 1
		if f == len(path) {
			openfile, err := os.Open(filename, syscall.O_WRONLY|syscall.O_CREAT|syscall.O_EXCL, mode)
			if err != nil {
				return err
			} else {
				openfile.Chown(file.Uid, file.Gid)
				openfile.Write(b)
				openfile.Close()
				os.Chtimes(filename, file.Mtime_ns, file.Mtime_ns)
			}
		} else {
			err := os.Mkdir(path[i], 0755)
			if err != nil {
				return err
			}
		}
	}

	return nil
}
開發者ID:sstephens,項目名稱:sstephens1,代碼行數:57,代碼來源:send.go

示例8: ServeHTTP

func (proxy *Proxy) ServeHTTP(conn *http.Conn, req *http.Request) {

	// Open a connection to the Hub.
	hubconn, err := net.Dial("tcp", "", remoteAddr)
	if err != nil {
		if debugMode {
			fmt.Printf("Couldn't connect to remote %s: %v\n", remoteHost, err)
		}
		return
	}

	hub := tls.Client(hubconn, tlsconf.Config)
	defer hub.Close()

	// Modify the request Host: header.
	req.Host = remoteHost

	// Send the request to the Hub.
	err = req.Write(hub)
	if err != nil {
		if debugMode {
			fmt.Printf("Error writing to the hub: %v\n", err)
		}
		return
	}

	// Parse the response from the Hub.
	resp, err := http.ReadResponse(bufio.NewReader(hub), req.Method)
	if err != nil {
		if debugMode {
			fmt.Printf("Error parsing response from the hub: %v\n", err)
		}
		return
	}

	// Set the received headers back to the initial connection.
	for k, v := range resp.Header {
		conn.SetHeader(k, v)
	}

	// Read the full response body.
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		if debugMode {
			fmt.Printf("Error reading response from the hub: %v\n", err)
		}
		resp.Body.Close()
		return
	}

	// Write the response body back to the initial connection.
	resp.Body.Close()
	conn.WriteHeader(resp.StatusCode)
	conn.Write(body)

}
開發者ID:evangineer,項目名稱:ampify,代碼行數:56,代碼來源:hubproxy.go

示例9: get

func get(p string, accept string) (r *http.Response, err os.Error) {
	var conn net.Conn
	if conn, err = net.Dial("tcp", fmt.Sprintf("localhost:%v", port())); err == nil {
		req, _ := http.NewRequest("GET", fmt.Sprintf("http://%v", path.Join(fmt.Sprintf("localhost:%v/", port()), p)), nil)
		req.Header.Set("Accept-Encoding", accept)
		req.Write(conn)
		buf := bufio.NewReader(conn)
		r, err = http.ReadResponse(buf, req)
	}
	return
}
開發者ID:repos-go,項目名稱:falcore,代碼行數:11,代碼來源:compression_test.go

示例10: send

func send(req *http.Request) (resp *http.Response, err os.Error) {
	if req.URL.Scheme != "http" && req.URL.Scheme != "https" {
		return nil, nil
	}

	addr := req.URL.Host
	if !hasPort(addr) {
		addr += ":" + req.URL.Scheme
	}
	/*info := req.URL.Userinfo
	  if len(info) > 0 {
	      enc := base64.URLEncoding
	      encoded := make([]byte, enc.EncodedLen(len(info)))
	      enc.Encode(encoded, []byte(info))
	      if req.Header == nil {
	          req.Header = make(map[string]string)
	      }
	      req.Header["Authorization"] = "Basic " + string(encoded)
	  }
	*/
	var conn io.ReadWriteCloser
	if req.URL.Scheme == "http" {
		conn, err = net.Dial("tcp", addr)
	} else { // https
		conn, err = tls.Dial("tcp", addr, nil)
	}
	if err != nil {
		return nil, err
	}

	err = req.Write(conn)
	if err != nil {
		conn.Close()
		return nil, err
	}

	reader := bufio.NewReader(conn)
	resp, err = http.ReadResponse(reader, req)
	if err != nil {
		conn.Close()
		return nil, err
	}

	resp.Body = readClose{resp.Body, conn}

	return
}
開發者ID:hokapoka,項目名稱:goauth,代碼行數:47,代碼來源:http.go

示例11: ReadResponse

// ReadResponse waits for a signal that the reqid request is complete.
// It uses http.ReadResponse to read and return an http.Response object from reqid's
// response buffer.
// After the response is read, the reqid is freed, and might immediately be used
// again for a new request.
func (ws *wsConn) ReadResponse(reqid uint16, method string) (ret *http.Response, err os.Error) {
	<-ws.signals[reqid] // wait for this reqid to be finished
	defer ws.freeReqId(reqid)
	buf := ws.buffers[reqid]
	content := buf.Bytes()
	findBytes := []byte("\r\n\r\n")
	i := bytes.Index(content, findBytes)
	if i >= 0 {
		length := "\r\nContent-Length: " + strconv.Itoa(len(content[i+4:]))
		newContent := make([]byte, 0, len(content)+len(length))
		buf = bytes.NewBuffer(newContent)
		buf.Write(content[:i])
		buf.Write([]byte(length))
		buf.Write(content[i:])
	}
	return http.ReadResponse(bufio.NewReader(buf), method)
}
開發者ID:gnanderson,項目名稱:fcgigo,代碼行數:22,代碼來源:handler.go

示例12: send

func send(req *http.Request) (resp *http.Response, err os.Error) {
	//dump, _ := http.DumpRequest(req, true)
	//fmt.Fprintf(os.Stderr, "%s", dump)
	//fmt.Fprintf(os.Stderr, "\n--- body:\n%s\n---", bodyString(req.Body))
	if req.URL.Scheme != "http" && req.URL.Scheme != "https" {
		return nil, &badStringError{"unsupported protocol scheme", req.URL.Scheme}
	}

	addr := req.URL.Host
	var conn net.Conn
	switch req.URL.Scheme {
	case "http":
		if !hasPort(addr) {
			addr += ":http"
		}

		conn, err = net.Dial("tcp", addr)
	case "https":
		if !hasPort(addr) {
			addr += ":https"
		}

		conn, err = tls.Dial("tcp", addr, nil)
	}
	if err != nil {
		return nil, err
	}

	err = req.Write(conn)
	if err != nil {
		conn.Close()
		return nil, err
	}

	reader := bufio.NewReader(conn)
	resp, err = http.ReadResponse(reader, req)
	if err != nil {
		conn.Close()
		return nil, err
	}

	resp.Body = readClose{resp.Body, conn}

	return
}
開發者ID:dustywilson,項目名稱:goauth,代碼行數:45,代碼來源:http.go

示例13: DialHTTP

// DialHTTP connects to an HTTP RPC server at the specified network address.
func DialHTTP(network, address string) (*Client, os.Error) {
	conn, err := net.Dial(network, "", address);
	if err != nil {
		return nil, err;
	}
	io.WriteString(conn, "CONNECT " + rpcPath + " HTTP/1.0\n\n");

	// Require successful HTTP response
	// before switching to RPC protocol.
	resp, err := http.ReadResponse(bufio.NewReader(conn));
	if err == nil && resp.Status == connected {
		return NewClient(conn), nil;
	}
	if err == nil {
		err = os.ErrorString("unexpected HTTP response: " + resp.Status);
	}
	conn.Close();
	return nil, &net.OpError{"dial-http", network+" "+address, nil, err};
}
開發者ID:8l,項目名稱:go-learn,代碼行數:20,代碼來源:client.go

示例14: sendPost

func sendPost(postRequest *http.Request) (body string, err os.Error) {
	// Create and use TCP connection (lifted mostly wholesale from http.send)
	conn, err := net.Dial("tcp", "api.flickr.com:80")
	defer conn.Close()

	if err != nil {
		return "", err
	}
	postRequest.Write(conn)

	reader := bufio.NewReader(conn)
	resp, err := http.ReadResponse(reader, postRequest.Method)
	if err != nil {
		return "", err
	}
	rawBody, _ := ioutil.ReadAll(resp.Body)

	return string(rawBody), nil
}
開發者ID:sarawuth,項目名稱:go-flickr,代碼行數:19,代碼來源:flickr.go

示例15: main

func main() {
	url := "http://twitter.com/statuses/public_timeline.json"
	var req http.Request
	req.URL, _ = http.ParseURL(url)
	addr := req.URL.Host
	addr += ":http"
	conn, _ := net.Dial("tcp", "", addr)
	_ = req.Write(conn)
	reader := bufio.NewReader(conn)
	resp, _ := http.ReadResponse(reader)
	r := io.Reader(reader)
	if v := resp.GetHeader("Content-Length"); v != "" {
		n, _ := strconv.Atoi64(v)
		r = io.LimitReader(r, n)
	}
	resp.Body = readClose{r, conn}
	b, _ := io.ReadAll(resp.Body)
	resp.Body.Close()
	fmt.Println(string(b))
}
開發者ID:syttru,項目名稱:syttru_scratch,代碼行數:20,代碼來源:httptest.go


注:本文中的http.ReadResponse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。