HTTP Version Not Supported
来源:9-4 测试http服务器(上)

weibo_北桥_03164202
2020-05-01
老师好,httptest的时候报错,请问下是什么原因,这个是源码
func TestErrorWrapper(t *testing.T) {
tests := []struct {
ahe AppHandlerErr
code int
message string
}{
{he, http.StatusInternalServerError, ""},
{heUE, http.StatusBadRequest, "自定义"},
}
for _, testObj := range tests {
appHandler := ErrorWrapper(testObj.ahe)
response := httptest.NewRecorder()
request := httptest.NewRequest(http.MethodGet, "http://www.imooc.com", nil)
appHandler(response, request)
buffer, _ := ioutil.ReadAll(response.Body)
code := response.Code
var body = strings.Trim(string(buffer), "\n")
if testObj.code != code || body != testObj.message {
t.Errorf("get(%d, message:%s),not %d,%s", code, body, testObj.code, testObj.message)
}
}
}
=== RUN TestErrorWrapper
2020/05/01 21:28:48 unknow pro 123
TestErrorWrapper: web_test.go:42: get(505, message:HTTP Version Not Supported),not 500,
2020/05/01 21:28:48 unknow pro 自定义
TestErrorWrapper: web_test.go:42: get(505, message:HTTP Version Not Supported),not 400,自定义
— FAIL: TestErrorWrapper (0.01s)
FAIL
Process finished with exit code 1
写回答
1回答
-
ccmouse
2020-05-02
这个是ErrorWrapper或是he/heUE两个函数逻辑有错。可以用调试器单步跟踪的方法查找错误。
还有是通过505, HTTP Version Not Supported,StatusHTTPVersionNotSupported 等特征字符串去搜索你自己的代码,看哪里有返回这些。
00
相似问题