Пример #1
0
func testPOST(serviceDomain string, useTLS bool) {
	var contentLength uint64 = 1024 * 1024 * 1024
	fog.Debug("start post %dmb", contentLength/(1024*1024))

	client, scheme := getClient(useTLS)

	url := fmt.Sprintf("%s://%s/admin", scheme, serviceDomain)
	bodyReader := tools.NewSizeReader(contentLength)
	request, err := http.NewRequest("POST", url, bodyReader)
	if err != nil {
		fog.Critical("NewRequest (POST) failed %s", err)
	}
	request.TransferEncoding = []string{"identity"}
	request.Header.Add("Content-Type", "text/plain")
	request.Header.Add("Content-Length", fmt.Sprintf("%s", contentLength))
	request.ContentLength = int64(contentLength)
	response, err := client.Do(request)
	if err != nil {
		fog.Error("post %s", err)
		return
	}
	tools.ReadAndDiscard(response.Body)
	response.Body.Close()

	fog.Debug("finished post %s", response.Status)
}
Пример #2
0
func (s serverImpl) handlePOST(w http.ResponseWriter, req *http.Request) {
	fog.Debug("(%s) got request %s %s", s.Name, req.Method, req.URL)
	if req.Body != nil {
		tools.ReadAndDiscard(req.Body)
		req.Body.Close()
	}
	io.WriteString(w, "hello, world!\n")
}
Пример #3
0
func (s serverImpl) handleGET(w http.ResponseWriter, req *http.Request) {
	fog.Debug("(%s) got request %s %s", s.Name, req.Method, req.URL)
	if req.Body != nil {
		tools.ReadAndDiscard(req.Body)
		req.Body.Close()
	}

	var contentLength uint64 = 1024 * 1024 * 1024
	fog.Debug("response body %dmb", contentLength/(1024*1024))
	bodyReader := tools.NewSizeReader(contentLength)

	http.ServeContent(w, req, "content.txt", time.Now(), bodyReader)
}
Пример #4
0
func testGET(serviceDomain string, useTLS bool) {

	fog.Debug("start get")

	client, scheme := getClient(useTLS)

	url := fmt.Sprintf("%s://%s/admin", scheme, serviceDomain)
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		fog.Critical("NewRequest (GET) failed %s", err)
	}
	response, err := client.Do(request)
	if err != nil {
		fog.Error("get %s", err)
		return
	}

	fog.Debug("reading GET response body")
	tools.ReadAndDiscard(response.Body)
	response.Body.Close()

	fog.Debug("finished get %s", response.Status)
}