(t *testing.T)
| 1752 | } |
| 1753 | |
| 1754 | func TestServerHTTP10ConnectionKeepAlive(t *testing.T) { |
| 1755 | t.Parallel() |
| 1756 | |
| 1757 | ln := fasthttputil.NewInmemoryListener() |
| 1758 | |
| 1759 | ch := make(chan struct{}) |
| 1760 | go func() { |
| 1761 | err := Serve(ln, func(ctx *RequestCtx) { |
| 1762 | if string(ctx.Path()) == "/close" { |
| 1763 | ctx.SetConnectionClose() |
| 1764 | } |
| 1765 | }) |
| 1766 | if err != nil { |
| 1767 | t.Errorf("unexpected error: %v", err) |
| 1768 | } |
| 1769 | close(ch) |
| 1770 | }() |
| 1771 | |
| 1772 | conn, err := ln.Dial() |
| 1773 | if err != nil { |
| 1774 | t.Fatalf("unexpected error: %v", err) |
| 1775 | } |
| 1776 | _, err = fmt.Fprintf(conn, "%s", "GET / HTTP/1.0\r\nHost: aaa\r\nConnection: keep-alive\r\n\r\n") |
| 1777 | if err != nil { |
| 1778 | t.Fatalf("error when writing request: %v", err) |
| 1779 | } |
| 1780 | _, err = fmt.Fprintf(conn, "%s", "GET /close HTTP/1.0\r\nHost: aaa\r\nConnection: keep-alive\r\n\r\n") |
| 1781 | if err != nil { |
| 1782 | t.Fatalf("error when writing request: %v", err) |
| 1783 | } |
| 1784 | |
| 1785 | br := bufio.NewReader(conn) |
| 1786 | var resp Response |
| 1787 | if err = resp.Read(br); err != nil { |
| 1788 | t.Fatalf("error when reading response: %v", err) |
| 1789 | } |
| 1790 | if resp.ConnectionClose() { |
| 1791 | t.Fatal("response mustn't have 'Connection: close' header") |
| 1792 | } |
| 1793 | if err = resp.Read(br); err != nil { |
| 1794 | t.Fatalf("error when reading response: %v", err) |
| 1795 | } |
| 1796 | if !resp.ConnectionClose() { |
| 1797 | t.Fatal("response must have 'Connection: close' header") |
| 1798 | } |
| 1799 | |
| 1800 | tailCh := make(chan struct{}) |
| 1801 | go func() { |
| 1802 | tail, err := io.ReadAll(br) |
| 1803 | if err != nil { |
| 1804 | t.Errorf("error when reading tail: %v", err) |
| 1805 | } |
| 1806 | if len(tail) > 0 { |
| 1807 | t.Errorf("unexpected non-zero tail %q", tail) |
| 1808 | } |
| 1809 | close(tailCh) |
| 1810 | }() |
| 1811 |
nothing calls this directly
no test coverage detected
searching dependent graphs…