add query handling

This commit is contained in:
Patricio Whittingslow
2026-07-25 22:45:59 -03:00
parent 268c7a6d5f
commit d5a5e44ddf
6 changed files with 447 additions and 7 deletions
+11 -3
View File
@@ -3,6 +3,8 @@ package httphi
import (
"io"
"testing"
"github.com/soypat/lneto/internal"
)
// benchConn replays a fixed request and discards the response. It allocates
@@ -48,17 +50,23 @@ func benchExchange(b *testing.B, conn conn) *Exchange {
// BenchmarkHandle measures a whole exchange: read, parse, mux and respond.
func BenchmarkHandle(b *testing.B) {
expect := []byte("123")
buf := make([]byte, 64)
for _, bb := range []struct {
name string
request string
handler HandlerFunc
}{
{
name: "GETWithHeaders",
request: "GET / HTTP/1.1\r\nHost: tinygo.org\r\nUser-Agent: bench\r\nAccept: */*\r\nConnection: close\r\n\r\n",
name: "GETWithHeadersAndQuery",
request: "GET /?abc=123 HTTP/1.1\r\nHost: tinygo.org\r\nUser-Agent: bench\r\nAccept: */*\r\nConnection: close\r\n\r\n",
handler: func(ex *Exchange) {
ex.SetHeader("Content-Type", "text/plain")
ex.SetHeaderInt("Content-Length", int64(len(benchBody)), 10)
data, present := ex.AppendQuery(buf[:0], "abc", true)
if !present || !internal.BytesEqual(data, expect) {
panic("invalid result")
}
ex.Write(benchBody)
},
},
@@ -78,7 +86,7 @@ func BenchmarkHandle(b *testing.B) {
b.ReportAllocs()
b.SetBytes(int64(len(bb.request)))
b.ResetTimer()
for b.Loop() {
for i := 0; i < b.N; i++ {
conn.rewind()
exch.Release()
exch.Acquire(conn)