diff options
author | Matus Fabian <matfabia@cisco.com> | 2024-10-17 13:41:51 +0200 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2024-10-25 23:33:15 +0000 |
commit | 841672258a55defb28b1ca6a35b6ad9830c132cf (patch) | |
tree | d9a0fa5366f5c53c8040b03e0904ee2569562b40 /extras | |
parent | dced40dcaca0186d11eccbf5c75e21446db931b9 (diff) |
http: pass timeout using extended config
App can now pass http connection timeout using extended configuration,
ext cfg type TRANSPORT_ENDPT_EXT_CFG_HTTP, value (in seconds) set in ext
cfg member opaque.
It is optional, default value is 60 seconds.
Type: improvement
Change-Id: Ibeff4bbd3153421be350ff564ec3c8e52e5b9639
Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'extras')
-rw-r--r-- | extras/hs-test/http_test.go | 36 | ||||
-rw-r--r-- | extras/hs-test/infra/utils.go | 2 |
2 files changed, 35 insertions, 3 deletions
diff --git a/extras/hs-test/http_test.go b/extras/hs-test/http_test.go index 982cab77d80..0b345d140ff 100644 --- a/extras/hs-test/http_test.go +++ b/extras/hs-test/http_test.go @@ -32,7 +32,7 @@ func init() { HttpInvalidContentLengthTest, HttpInvalidTargetSyntaxTest, HttpStaticPathTraversalTest, HttpUriDecodeTest, HttpHeadersTest, HttpStaticFileHandlerTest, HttpStaticFileHandlerDefaultMaxAgeTest, HttpClientTest, HttpClientErrRespTest, HttpClientPostFormTest, HttpClientPostFileTest, HttpClientPostFilePtrTest, AuthorityFormTargetTest, HttpRequestLineTest, - HttpStaticFileHandlerWrkTest, HttpStaticUrlHandlerWrkTest) + HttpStaticFileHandlerWrkTest, HttpStaticUrlHandlerWrkTest, HttpConnTimeoutTest) RegisterNoTopoSoloTests(HttpStaticPromTest, HttpGetTpsTest, HttpGetTpsInterruptModeTest, PromConcurrentConnectionsTest, PromMemLeakTest, HttpClientPostMemLeakTest, HttpInvalidClientRequestMemLeakTest, HttpPostTpsTest, HttpPostTpsInterruptModeTest, PromConsecutiveConnectionsTest) @@ -804,10 +804,10 @@ func HttpCliBadRequestTest(s *NoTopoSuite) { func HttpStaticBuildInUrlGetVersionTest(s *NoTopoSuite) { vpp := s.GetContainerByName("vpp").VppInstance serverAddress := s.VppAddr() - s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) + s.Log(vpp.Vppctl("http static server uri tls://" + serverAddress + "/80 url-handlers debug")) client := NewHttpClient(defaultHttpTimeout) - req, err := http.NewRequest("GET", "http://"+serverAddress+":80/version.json", nil) + req, err := http.NewRequest("GET", "https://"+serverAddress+":80/version.json", nil) s.AssertNil(err, fmt.Sprint(err)) resp, err := client.Do(req) s.AssertNil(err, fmt.Sprint(err)) @@ -1205,3 +1205,33 @@ func HeaderServerTest(s *NoTopoSuite) { s.AssertHttpHeaderWithValue(resp, "Server", "http_cli_server") s.AssertHttpHeaderWithValue(resp, "Content-Type", "text/html") } + +func HttpConnTimeoutTest(s *NoTopoSuite) { + vpp := s.GetContainerByName("vpp").VppInstance + serverAddress := s.VppAddr() + s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug keepalive-timeout 2")) + + req := "GET /version.json HTTP/1.1\r\nHost:" + serverAddress + ":80\r\nUser-Agent:test\r\n\r\n" + conn, err := net.DialTimeout("tcp", serverAddress+":80", time.Second*30) + s.AssertNil(err, fmt.Sprint(err)) + defer conn.Close() + err = conn.SetDeadline(time.Now().Add(time.Second * 30)) + s.AssertNil(err, fmt.Sprint(err)) + _, err = conn.Write([]byte(req)) + s.AssertNil(err, fmt.Sprint(err)) + reply := make([]byte, 1024) + _, err = conn.Read(reply) + s.AssertNil(err, fmt.Sprint(err)) + s.AssertContains(string(reply), "HTTP/1.1 200 OK") + s.Log(vpp.Vppctl("show session verbose 2")) + + s.Log("waiting for close on the server side") + time.Sleep(time.Second * 5) + s.Log(vpp.Vppctl("show session verbose 2")) + + _, err = conn.Write([]byte(req)) + s.AssertNil(err, fmt.Sprint(err)) + reply = make([]byte, 1024) + _, err = conn.Read(reply) + s.AssertMatchError(err, io.EOF, "connection not closed by server") +} diff --git a/extras/hs-test/infra/utils.go b/extras/hs-test/infra/utils.go index c5e5cc7cdc5..30abb6ac715 100644 --- a/extras/hs-test/infra/utils.go +++ b/extras/hs-test/infra/utils.go @@ -1,6 +1,7 @@ package hst import ( + "crypto/tls" "errors" "fmt" "io" @@ -90,6 +91,7 @@ func NewHttpClient(timeout time.Duration) *http.Client { transport := http.DefaultTransport transport.(*http.Transport).Proxy = nil transport.(*http.Transport).DisableKeepAlives = true + transport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} client := &http.Client{ Transport: transport, Timeout: timeout, |