// Send! // // @return string // @panics func (this *Request) Send() string { link, err := _net.Dial("tcp", _fmt.Sprintf("%s:%v", this.Config["Host"], this.Config["Port"])) if err != nil { panic(err) } defer link.Close() var send, recv string url := util.ParseUrl(_fmt.Sprintf("%s://%s", this.Config["Scheme"], this.Uri)) // add first line & headers send += _fmt.Sprintf("%s %s?%s HTTP/%s\r\n", this.Method, url["Path"], url["Query"], this.HttpVersion) for key, value := range this.Headers { if !util.IsEmpty(value) { send += _fmt.Sprintf("%s: %s\r\n", key, value) } } send += "\r\n" send += this.GetBody() _fmt.Fprint(link, send) reader := _bio.NewReader(link) status, err := reader.ReadString('\n') if status == "" { print("HTTP error: no response returned from server!\n") print("---------------------------------------------\n") print(send) print("---------------------------------------------\n") panic(err) } recv += status for { buffer := make([]byte, 1024) if read, _ := reader.Read(buffer); read == 0 { break // eof } // yes, we've allocated to much.. recv += _str.Trim(string(buffer), "\x00") } // @debug if this.Config["Couch.DEBUG"] == true { util.Dump(send) util.Dump(recv) } return recv }
/** * TestAll */ func TestAll() { // status TestClientResponseStatus() TestClientResponseStatusCode() TestClientResponseStatusText() util.Dump("") // headers TestClientResponseHeaders("") TestClientResponseHeaders("0") // status line TestClientResponseHeaders("Server") util.Dump("") // body TestClientResponseBody() util.Dump("") // body parsed TestClientResponseData() }