[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-4764":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":25,"hasPages":23,"topics":26,"createdAt":10,"pushedAt":10,"updatedAt":27,"readmeContent":28,"aiSummary":29,"trendingCount":16,"starSnapshotCount":16,"syncStatus":30,"lastSyncTime":31,"discoverSource":32},4764,"fasthttp","valyala\u002Ffasthttp","valyala","Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net\u002Fhttp","",null,"Go",23374,1825,384,78,0,4,8,33,14,85.08,"MIT License",false,"master",true,[],"2026-06-12 04:00:22","# fasthttp\n\n[![Go Reference](https:\u002F\u002Fpkg.go.dev\u002Fbadge\u002Fgithub.com\u002Fvalyala\u002Ffasthttp)](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp) [![Go Report](https:\u002F\u002Fgoreportcard.com\u002Fbadge\u002Fgithub.com\u002Fvalyala\u002Ffasthttp)](https:\u002F\u002Fgoreportcard.com\u002Freport\u002Fgithub.com\u002Fvalyala\u002Ffasthttp)\n\n![FastHTTP – Fastest and reliable HTTP implementation in Go](https:\u002F\u002Fgithub.com\u002Ffasthttp\u002Fdocs-assets\u002Fraw\u002Fmaster\u002Fbanner@0.5.png)\n\nFast HTTP implementation for Go.\n\n## fasthttp might not be for you!\n\nfasthttp was designed for some high performance edge cases. **Unless** your server\u002Fclient needs to handle **thousands of small to medium requests per second** and needs a consistent low millisecond response time fasthttp might not be for you. **For most cases `net\u002Fhttp` is much better** as it's easier to use and can handle more cases. For most cases you won't even notice the performance difference.\n\n## General info and links\n\nCurrently fasthttp is successfully used by [VertaMedia](https:\u002F\u002Fvertamedia.com\u002F)\nin a production serving up to 200K rps from more than 1.5M concurrent keep-alive\nconnections per physical server.\n\n[TechEmpower Benchmark round 23 results](https:\u002F\u002Fwww.techempower.com\u002Fbenchmarks\u002F#section=data-r23&hw=ph&test=plaintext)\n\n[Server Benchmarks](#http-server-performance-comparison-with-nethttp)\n\n[Client Benchmarks](#http-client-comparison-with-nethttp)\n\n[Install](#install)\n\n[Documentation](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp)\n\n[Examples from docs](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#pkg-examples)\n\n[Code examples](examples)\n\n[Awesome fasthttp tools](https:\u002F\u002Fgithub.com\u002Ffasthttp)\n\n[Switching from net\u002Fhttp to fasthttp](#switching-from-nethttp-to-fasthttp)\n\n[Fasthttp best practices](#fasthttp-best-practices)\n\n[Related projects](#related-projects)\n\n[FAQ](#faq)\n\n## HTTP server performance comparison with [net\u002Fhttp](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp)\n\nIn short, fasthttp server is up to 6 times faster than net\u002Fhttp.\nBelow are benchmark results.\n\n_GOMAXPROCS=1_\n\nnet\u002Fhttp server:\n\n```\n$ GOMAXPROCS=1 go test -bench=NetHTTPServerGet -benchmem -benchtime=10s\ncpu: Intel(R) Xeon(R) CPU @ 2.20GHz\nBenchmarkNetHTTPServerGet1ReqPerConn                      722565             15327 ns\u002Fop            3258 B\u002Fop         36 allocs\u002Fop\nBenchmarkNetHTTPServerGet2ReqPerConn                      990067             11533 ns\u002Fop            2817 B\u002Fop         28 allocs\u002Fop\nBenchmarkNetHTTPServerGet10ReqPerConn                    1376821              8734 ns\u002Fop            2483 B\u002Fop         23 allocs\u002Fop\nBenchmarkNetHTTPServerGet10KReqPerConn                   1691265              7151 ns\u002Fop            2385 B\u002Fop         21 allocs\u002Fop\nBenchmarkNetHTTPServerGet1ReqPerConn10KClients            643940             17152 ns\u002Fop            3529 B\u002Fop         36 allocs\u002Fop\nBenchmarkNetHTTPServerGet2ReqPerConn10KClients            868576             14010 ns\u002Fop            2826 B\u002Fop         28 allocs\u002Fop\nBenchmarkNetHTTPServerGet10ReqPerConn10KClients          1297398              9329 ns\u002Fop            2611 B\u002Fop         23 allocs\u002Fop\nBenchmarkNetHTTPServerGet100ReqPerConn10KClients         1467963              7902 ns\u002Fop            2450 B\u002Fop         21 allocs\u002Fop\n```\n\nfasthttp server:\n\n```\n$ GOMAXPROCS=1 go test -bench=kServerGet -benchmem -benchtime=10s\ncpu: Intel(R) Xeon(R) CPU @ 2.20GHz\nBenchmarkServerGet1ReqPerConn                    4304683              2733 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet2ReqPerConn                    5685157              2140 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet10ReqPerConn                   7659729              1550 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet10KReqPerConn                  8580660              1422 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet1ReqPerConn10KClients          4092148              3009 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet2ReqPerConn10KClients          5272755              2208 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet10ReqPerConn10KClients         7566351              1546 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet100ReqPerConn10KClients        8369295              1418 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\n```\n\n_GOMAXPROCS=4_\n\nnet\u002Fhttp server:\n\n```\n$ GOMAXPROCS=4 go test -bench=NetHTTPServerGet -benchmem -benchtime=10s\ncpu: Intel(R) Xeon(R) CPU @ 2.20GHz\nBenchmarkNetHTTPServerGet1ReqPerConn-4                   2670654              4542 ns\u002Fop            3263 B\u002Fop         36 allocs\u002Fop\nBenchmarkNetHTTPServerGet2ReqPerConn-4                   3376021              3559 ns\u002Fop            2823 B\u002Fop         28 allocs\u002Fop\nBenchmarkNetHTTPServerGet10ReqPerConn-4                  4387959              2707 ns\u002Fop            2489 B\u002Fop         23 allocs\u002Fop\nBenchmarkNetHTTPServerGet10KReqPerConn-4                 5412049              2179 ns\u002Fop            2386 B\u002Fop         21 allocs\u002Fop\nBenchmarkNetHTTPServerGet1ReqPerConn10KClients-4         2226048              5216 ns\u002Fop            3289 B\u002Fop         36 allocs\u002Fop\nBenchmarkNetHTTPServerGet2ReqPerConn10KClients-4         2989957              3982 ns\u002Fop            2839 B\u002Fop         28 allocs\u002Fop\nBenchmarkNetHTTPServerGet10ReqPerConn10KClients-4        4383570              2834 ns\u002Fop            2514 B\u002Fop         23 allocs\u002Fop\nBenchmarkNetHTTPServerGet100ReqPerConn10KClients-4       5315100              2394 ns\u002Fop            2419 B\u002Fop         21 allocs\u002Fop\n```\n\nfasthttp server:\n\n```\n$ GOMAXPROCS=4 go test -bench=kServerGet -benchmem -benchtime=10s\ncpu: Intel(R) Xeon(R) CPU @ 2.20GHz\nBenchmarkServerGet1ReqPerConn-4                  7797037              1494 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet2ReqPerConn-4                 13004892               963.7 ns\u002Fop             0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet10ReqPerConn-4                22479348               522.6 ns\u002Fop             0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet10KReqPerConn-4               25899390               451.4 ns\u002Fop             0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet1ReqPerConn10KClients-4        8421531              1469 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet2ReqPerConn10KClients-4       13426772               903.7 ns\u002Fop             0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet10ReqPerConn10KClients-4      21899584               513.5 ns\u002Fop             0 B\u002Fop          0 allocs\u002Fop\nBenchmarkServerGet100ReqPerConn10KClients-4     25291686               439.4 ns\u002Fop             0 B\u002Fop          0 allocs\u002Fop\n```\n\n## HTTP client comparison with net\u002Fhttp\n\nIn short, fasthttp client is up to 4 times faster than net\u002Fhttp.\nBelow are benchmark results.\n\n_GOMAXPROCS=1_\n\nnet\u002Fhttp client:\n\n```\n$ GOMAXPROCS=1 go test -bench='HTTPClient(Do|GetEndToEnd)' -benchmem -benchtime=10s\ncpu: Intel(R) Xeon(R) CPU @ 2.20GHz\nBenchmarkNetHTTPClientDoFastServer                        885637             13883 ns\u002Fop            3384 B\u002Fop         44 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEnd1TCP                     203875             55619 ns\u002Fop            6296 B\u002Fop         70 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEnd10TCP                    231290             54618 ns\u002Fop            6299 B\u002Fop         70 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEnd100TCP                   202879             58278 ns\u002Fop            6304 B\u002Fop         69 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEnd1Inmemory                396764             26878 ns\u002Fop            6216 B\u002Fop         69 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEnd10Inmemory               396422             28373 ns\u002Fop            6209 B\u002Fop         68 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEnd100Inmemory              363976             33101 ns\u002Fop            6326 B\u002Fop         68 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEnd1000Inmemory             208881             51725 ns\u002Fop            8298 B\u002Fop         84 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEndWaitConn1Inmemory           237          50451765 ns\u002Fop            7474 B\u002Fop         79 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEndWaitConn10Inmemory          237          50447244 ns\u002Fop            7434 B\u002Fop         77 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEndWaitConn100Inmemory         238          50067993 ns\u002Fop            8639 B\u002Fop         82 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEndWaitConn1000Inmemory       1366           7324990 ns\u002Fop            4064 B\u002Fop         44 allocs\u002Fop\n```\n\nfasthttp client:\n\n```\n$ GOMAXPROCS=1 go test -bench='kClient(Do|GetEndToEnd)' -benchmem -benchtime=10s\ncpu: Intel(R) Xeon(R) CPU @ 2.20GHz\nBenchmarkClientGetEndToEnd1TCP                    406376             26558 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd10TCP                   517425             23595 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd100TCP                  474800             25153 ns\u002Fop               3 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd1Inmemory              2563800              4827 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd10Inmemory             2460135              4805 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd100Inmemory            2520543              4846 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd1000Inmemory           2437015              4914 ns\u002Fop               2 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd10KInmemory            2481050              5049 ns\u002Fop               9 B\u002Fop          0 allocs\u002Fop\n```\n\n_GOMAXPROCS=4_\n\nnet\u002Fhttp client:\n\n```\n$ GOMAXPROCS=4 go test -bench='HTTPClient(Do|GetEndToEnd)' -benchmem -benchtime=10s\ncpu: Intel(R) Xeon(R) CPU @ 2.20GHz\nBenchmarkNetHTTPClientGetEndToEnd1TCP-4                           767133             16175 ns\u002Fop            6304 B\u002Fop         69 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEnd10TCP-4                          785198             15276 ns\u002Fop            6295 B\u002Fop         69 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEnd100TCP-4                         780464             15605 ns\u002Fop            6305 B\u002Fop         69 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEnd1Inmemory-4                     1356932              8772 ns\u002Fop            6220 B\u002Fop         68 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEnd10Inmemory-4                    1379245              8726 ns\u002Fop            6213 B\u002Fop         68 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEnd100Inmemory-4                   1119213             10294 ns\u002Fop            6418 B\u002Fop         68 allocs\u002Fop\nBenchmarkNetHTTPClientGetEndToEnd1000Inmemory-4                   504194             31010 ns\u002Fop           17668 B\u002Fop        102 allocs\u002Fop\n```\n\nfasthttp client:\n\n```\n$ GOMAXPROCS=4 go test -bench='kClient(Do|GetEndToEnd)' -benchmem -benchtime=10s\ncpu: Intel(R) Xeon(R) CPU @ 2.20GHz\nBenchmarkClientGetEndToEnd1TCP-4                         1474552              8143 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd10TCP-4                        1710270              7186 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd100TCP-4                       1701672              6892 ns\u002Fop               4 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd1Inmemory-4                    6797713              1590 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd10Inmemory-4                   6663642              1782 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd100Inmemory-4                  6608209              1867 ns\u002Fop               0 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd1000Inmemory-4                 6254452              2645 ns\u002Fop               8 B\u002Fop          0 allocs\u002Fop\nBenchmarkClientGetEndToEnd10KInmemory-4                  6944584              1966 ns\u002Fop              17 B\u002Fop          0 allocs\u002Fop\n```\n\n## Install\n\n```\ngo get -u github.com\u002Fvalyala\u002Ffasthttp\n```\n\n## Switching from net\u002Fhttp to fasthttp\n\nUnfortunately, fasthttp doesn't provide API identical to net\u002Fhttp.\nSee the [FAQ](#faq) for details.\nThere is [net\u002Fhttp -> fasthttp handler converter](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp\u002Ffasthttpadaptor),\nbut it is better to write fasthttp request handlers by hand in order to use\nall of the fasthttp advantages (especially high performance :) ).\n\nImportant points:\n\n- Fasthttp works with [RequestHandler functions](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestHandler)\n  instead of objects implementing [Handler interface](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Handler).\n  Fortunately, it is easy to pass bound struct methods to fasthttp:\n\n  ```go\n  type MyHandler struct {\n  \tfoobar string\n  }\n\n  \u002F\u002F request handler in net\u002Fhttp style, i.e. method bound to MyHandler struct.\n  func (h *MyHandler) HandleFastHTTP(ctx *fasthttp.RequestCtx) {\n  \t\u002F\u002F notice that we may access MyHandler properties here - see h.foobar.\n  \tfmt.Fprintf(ctx, \"Hello, world! Requested path is %q. Foobar is %q\",\n  \t\tctx.Path(), h.foobar)\n  }\n\n  \u002F\u002F request handler in fasthttp style, i.e. just plain function.\n  func fastHTTPHandler(ctx *fasthttp.RequestCtx) {\n  \tfmt.Fprintf(ctx, \"Hi there! RequestURI is %q\", ctx.RequestURI())\n  }\n\n  \u002F\u002F pass bound struct method to fasthttp\n  myHandler := &MyHandler{\n  \tfoobar: \"foobar\",\n  }\n  fasthttp.ListenAndServe(\":8080\", myHandler.HandleFastHTTP)\n\n  \u002F\u002F pass plain function to fasthttp\n  fasthttp.ListenAndServe(\":8081\", fastHTTPHandler)\n  ```\n\n- The [RequestHandler](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestHandler)\n  accepts only one argument - [RequestCtx](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx).\n  It contains all the functionality required for http request processing\n  and response writing. Below is an example of a simple request handler conversion\n  from net\u002Fhttp to fasthttp.\n\n  ```go\n  \u002F\u002F net\u002Fhttp request handler\n  requestHandler := func(w http.ResponseWriter, r *http.Request) {\n  \tswitch r.URL.Path {\n  \tcase \"\u002Ffoo\":\n  \t\tfooHandler(w, r)\n  \tcase \"\u002Fbar\":\n  \t\tbarHandler(w, r)\n  \tdefault:\n  \t\thttp.Error(w, \"Unsupported path\", http.StatusNotFound)\n  \t}\n  }\n  ```\n\n  ```go\n  \u002F\u002F the corresponding fasthttp request handler\n  requestHandler := func(ctx *fasthttp.RequestCtx) {\n  \tswitch string(ctx.Path()) {\n  \tcase \"\u002Ffoo\":\n  \t\tfooHandler(ctx)\n  \tcase \"\u002Fbar\":\n  \t\tbarHandler(ctx)\n  \tdefault:\n  \t\tctx.Error(\"Unsupported path\", fasthttp.StatusNotFound)\n  \t}\n  }\n  ```\n\n- Fasthttp allows setting response headers and writing response body\n  in an arbitrary order. There is no 'headers first, then body' restriction\n  like in net\u002Fhttp. The following code is valid for fasthttp:\n\n  ```go\n  requestHandler := func(ctx *fasthttp.RequestCtx) {\n  \t\u002F\u002F set some headers and status code first\n  \tctx.SetContentType(\"foo\u002Fbar\")\n  \tctx.SetStatusCode(fasthttp.StatusOK)\n\n  \t\u002F\u002F then write the first part of body\n  \tfmt.Fprintf(ctx, \"this is the first part of body\\n\")\n\n  \t\u002F\u002F then set more headers\n  \tctx.Response.Header.Set(\"Foo-Bar\", \"baz\")\n\n  \t\u002F\u002F then write more body\n  \tfmt.Fprintf(ctx, \"this is the second part of body\\n\")\n\n  \t\u002F\u002F then override already written body\n  \tctx.SetBody([]byte(\"this is completely new body contents\"))\n\n  \t\u002F\u002F then update status code\n  \tctx.SetStatusCode(fasthttp.StatusNotFound)\n\n  \t\u002F\u002F basically, anything may be updated many times before\n  \t\u002F\u002F returning from RequestHandler.\n  \t\u002F\u002F\n  \t\u002F\u002F Unlike net\u002Fhttp fasthttp doesn't put response to the wire until\n  \t\u002F\u002F returning from RequestHandler.\n  }\n  ```\n\n- Fasthttp doesn't provide [ServeMux](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#ServeMux),\n  but there are more powerful third-party routers and web frameworks\n  with fasthttp support:\n\n  - [fasthttp-routing](https:\u002F\u002Fgithub.com\u002Fqiangxue\u002Ffasthttp-routing)\n  - [router](https:\u002F\u002Fgithub.com\u002Ffasthttp\u002Frouter)\n  - [lu](https:\u002F\u002Fgithub.com\u002FvincentLiuxiang\u002Flu)\n  - [atreugo](https:\u002F\u002Fgithub.com\u002Fsavsgio\u002Fatreugo)\n  - [Fiber](https:\u002F\u002Fgithub.com\u002Fgofiber\u002Ffiber)\n  - [Gearbox](https:\u002F\u002Fgithub.com\u002Fgogearbox\u002Fgearbox)\n\n  Net\u002Fhttp code with simple ServeMux is trivially converted to fasthttp code:\n\n  ```go\n  \u002F\u002F net\u002Fhttp code\n\n  m := &http.ServeMux{}\n  m.HandleFunc(\"\u002Ffoo\", fooHandlerFunc)\n  m.HandleFunc(\"\u002Fbar\", barHandlerFunc)\n  m.Handle(\"\u002Fbaz\", bazHandler)\n\n  http.ListenAndServe(\":80\", m)\n  ```\n\n  ```go\n  \u002F\u002F the corresponding fasthttp code\n  m := func(ctx *fasthttp.RequestCtx) {\n  \tswitch string(ctx.Path()) {\n  \tcase \"\u002Ffoo\":\n  \t\tfooHandlerFunc(ctx)\n  \tcase \"\u002Fbar\":\n  \t\tbarHandlerFunc(ctx)\n  \tcase \"\u002Fbaz\":\n  \t\tbazHandler.HandlerFunc(ctx)\n  \tdefault:\n  \t\tctx.Error(\"not found\", fasthttp.StatusNotFound)\n  \t}\n  }\n\n  fasthttp.ListenAndServe(\":80\", m)\n  ```\n\n- Because creating a new channel for every request is just too expensive, so the channel returned by RequestCtx.Done() is only closed when the server is shutting down.\n\n  ```go\n  func main() {\n  fasthttp.ListenAndServe(\":8080\", fasthttp.TimeoutHandler(func(ctx *fasthttp.RequestCtx) {\n  \tselect {\n  \tcase \u003C-ctx.Done():\n  \t\t\u002F\u002F ctx.Done() is only closed when the server is shutting down.\n  \t\tlog.Println(\"context cancelled\")\n  \t\treturn\n  \tcase \u003C-time.After(10 * time.Second):\n  \t\tlog.Println(\"process finished ok\")\n  \t}\n  }, time.Second*2, \"timeout\"))\n  }\n  ```\n\n- net\u002Fhttp -> fasthttp conversion table:\n\n  - All the pseudocode below assumes w, r and ctx have these types:\n\n  ```go\n  var (\n  \tw http.ResponseWriter\n  \tr *http.Request\n  \tctx *fasthttp.RequestCtx\n  )\n  ```\n\n  - [r.Body](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request) **➜** [ctx.PostBody()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.PostBody)\n  - [r.URL.Path](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Furl#URL) **➜** [ctx.Path()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.Path)\n  - [r.URL](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request) **➜** [ctx.URI()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.URI)\n  - [r.Method](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request) **➜** [ctx.Method()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.Method)\n  - [r.Header](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request) **➜** [ctx.Request.Header](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestHeader)\n  - [r.Header.Get()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Header.Get) **➜** [ctx.Request.Header.Peek()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestHeader.Peek)\n  - [r.Host](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request) **➜** [ctx.Host()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.Host)\n  - [r.Form](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request) **➜** [ctx.QueryArgs()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.QueryArgs) +\n    [ctx.PostArgs()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.PostArgs)\n  - [r.PostForm](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request) **➜** [ctx.PostArgs()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.PostArgs)\n  - [r.FormValue()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request.FormValue) **➜** [ctx.FormValue()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.FormValue)\n  - [r.FormFile()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request.FormFile) **➜** [ctx.FormFile()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.FormFile)\n  - [r.MultipartForm](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request) **➜** [ctx.MultipartForm()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.MultipartForm)\n    For untrusted multipart input, use [ctx.MultipartFormWithLimit()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.MultipartFormWithLimit) (or a custom [Server.FormValueFunc](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#Server)) to enforce a parsing size limit.\n  - [r.RemoteAddr](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request) **➜** [ctx.RemoteAddr()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.RemoteAddr)\n  - [r.RequestURI](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request) **➜** [ctx.RequestURI()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.RequestURI)\n  - [r.TLS](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request) **➜** [ctx.IsTLS()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.IsTLS)\n  - [r.Cookie()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request.Cookie) **➜** [ctx.Request.Header.Cookie()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestHeader.Cookie)\n  - [r.Referer()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request.Referer) **➜** [ctx.Referer()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.Referer)\n  - [r.UserAgent()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request.UserAgent) **➜** [ctx.UserAgent()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.UserAgent)\n  - [w.Header()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#ResponseWriter) **➜** [ctx.Response.Header](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#ResponseHeader)\n  - [w.Header().Set()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Header.Set) **➜** [ctx.Response.Header.Set()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#ResponseHeader.Set)\n  - [w.Header().Set(\"Content-Type\")](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Header.Set) **➜** [ctx.SetContentType()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.SetContentType)\n  - [w.Header().Set(\"Set-Cookie\")](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Header.Set) **➜** [ctx.Response.Header.SetCookie()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#ResponseHeader.SetCookie)\n  - [w.Write()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#ResponseWriter) **➜** [ctx.Write()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.Write),\n    [ctx.SetBody()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.SetBody),\n    [ctx.SetBodyStream()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.SetBodyStream),\n    [ctx.SetBodyStreamWriter()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.SetBodyStreamWriter)\n  - [w.WriteHeader()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#ResponseWriter) **➜** [ctx.SetStatusCode()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.SetStatusCode)\n  - [w.(http.Hijacker).Hijack()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Hijacker) **➜** [ctx.Hijack()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.Hijack)\n  - [http.Error()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Error) **➜** [ctx.Error()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.Error)\n  - [http.FileServer()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#FileServer) **➜** [fasthttp.FSHandler()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#FSHandler),\n    [fasthttp.FS](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#FS)\n  - [http.ServeFile()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#ServeFile) **➜** [fasthttp.ServeFile()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#ServeFile)\n  - [http.Redirect()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Redirect) **➜** [ctx.Redirect()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.Redirect)\n  - [http.NotFound()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#NotFound) **➜** [ctx.NotFound()](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.NotFound)\n  - [http.StripPrefix()](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#StripPrefix) **➜** [fasthttp.PathRewriteFunc](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#PathRewriteFunc)\n\n- _VERY IMPORTANT!_ Fasthttp disallows holding references\n  to [RequestCtx](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx) or to its'\n  members after returning from [RequestHandler](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestHandler).\n  Otherwise [data races](http:\u002F\u002Fgo.dev\u002Fblog\u002Frace-detector) are inevitable.\n  Carefully inspect all the net\u002Fhttp request handlers converted to fasthttp whether\n  they retain references to RequestCtx or to its' members after returning.\n  RequestCtx provides the following _band aids_ for this case:\n\n  - Wrap RequestHandler into [TimeoutHandler](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#TimeoutHandler).\n  - Call [TimeoutError](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.TimeoutError)\n    before returning from RequestHandler if there are references to RequestCtx or to its' members.\n    See [the example](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#example-RequestCtx-TimeoutError)\n    for more details.\n\nUse this brilliant tool - [race detector](http:\u002F\u002Fgo.dev\u002Fblog\u002Frace-detector) -\nfor detecting and eliminating data races in your program. If you detected\ndata race related to fasthttp in your program, then there is high probability\nyou forgot calling [TimeoutError](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.TimeoutError)\nbefore returning from [RequestHandler](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestHandler).\n\n- Blind switching from net\u002Fhttp to fasthttp won't give you performance boost.\n  While fasthttp is optimized for speed, its' performance may be easily saturated\n  by slow [RequestHandler](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestHandler).\n  So [profile](http:\u002F\u002Fgo.dev\u002Fblog\u002Fpprof) and optimize your\n  code after switching to fasthttp. For instance, use [quicktemplate](https:\u002F\u002Fgithub.com\u002Fvalyala\u002Fquicktemplate)\n  instead of [html\u002Ftemplate](https:\u002F\u002Fpkg.go.dev\u002Fhtml\u002Ftemplate).\n\n- See also [fasthttputil](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp\u002Ffasthttputil),\n  [fasthttpadaptor](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp\u002Ffasthttpadaptor) and\n  [expvarhandler](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp\u002Fexpvarhandler).\n\n## Performance optimization tips for multi-core systems\n\n- Use [reuseport](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp\u002Freuseport) listener.\n- Run a separate server instance per CPU core with GOMAXPROCS=1.\n- Pin each server instance to a separate CPU core using [taskset](http:\u002F\u002Flinux.die.net\u002Fman\u002F1\u002Ftaskset).\n- Ensure the interrupts of multiqueue network card are evenly distributed between CPU cores.\n  See [this article](https:\u002F\u002Fblog.cloudflare.com\u002Fhow-to-achieve-low-latency\u002F) for details.\n- Use the latest version of Go as each version contains performance improvements.\n\n## Fasthttp best practices\n\n- Do not allocate objects and `[]byte` buffers - just reuse them as much\n  as possible. Fasthttp API design encourages this.\n- [sync.Pool](https:\u002F\u002Fpkg.go.dev\u002Fsync#Pool) is your best friend.\n- [Profile your program](http:\u002F\u002Fgo.dev\u002Fblog\u002Fpprof)\n  in production.\n  `go tool pprof --alloc_objects your-program mem.pprof` usually gives better\n  insights for optimization opportunities than `go tool pprof your-program cpu.pprof`.\n- Write [tests and benchmarks](https:\u002F\u002Fpkg.go.dev\u002Ftesting) for hot paths.\n- Avoid conversion between `[]byte` and `string`, since this may result in memory\n  allocation+copy - see [this wiki page](https:\u002F\u002Fgithub.com\u002Fgolang\u002Fgo\u002Fwiki\u002FCompilerOptimizations#string-and-byte)\n  for more details.\n- Verify your tests and production code under\n  [race detector](https:\u002F\u002Fgo.dev\u002Fdoc\u002Farticles\u002Frace_detector.html) on a regular basis.\n- Prefer [quicktemplate](https:\u002F\u002Fgithub.com\u002Fvalyala\u002Fquicktemplate) instead of\n  [html\u002Ftemplate](https:\u002F\u002Fpkg.go.dev\u002Fhtml\u002Ftemplate) in your webserver.\n\n## Unsafe Zero-Allocation Conversions\n\nIn performance-critical code, converting between `[]byte` and `string` using standard Go allocations can be inefficient. To address this, `fasthttp` uses **unsafe**, zero-allocation helpers:\n\n> ⚠️ **Warning:** These conversions break Go's type safety. Use only when you're certain the converted value will not be mutated, as violating immutability can cause undefined behavior.\n\n### `UnsafeString(b []byte) string`\n\nConverts a `[]byte` to a `string` **without memory allocation**.\n\n```go\n\u002F\u002F UnsafeString returns a string pointer without allocation\nfunc UnsafeString(b []byte) string {\n    \u002F\u002F #nosec G103\n    return *(*string)(unsafe.Pointer(&b))\n}\n```\n\n### `UnsafeBytes(s string) []byte`\n\nConverts a `string` to a `[]byte` **without memory allocation**.\n\n```go\n\u002F\u002F UnsafeBytes returns a byte pointer without allocation.\nfunc UnsafeBytes(s string) []byte {\n    \u002F\u002F #nosec G103\n    return unsafe.Slice(unsafe.StringData(s), len(s))\n}\n```\n\n### Use Cases & Caveats\n\n- These functions are ideal for performance-sensitive scenarios where allocations must be avoided (e.g., request\u002Fresponse processing loops).\n- **Do not** mutate the `[]byte` returned from `UnsafeBytes(s string)` if the original string is still in use, as strings are immutable in Go and may be shared across the runtime.\n- Use samples guarded with `#nosec G103` comments to suppress static analysis warnings about unsafe operations.\n\n## Tricks with `[]byte` buffers\n\nThe following tricks are used by fasthttp. Use them in your code too.\n\n- Standard Go functions accept nil buffers\n\n```go\nvar (\n\t\u002F\u002F both buffers are uninitialized\n\tdst []byte\n\tsrc []byte\n)\ndst = append(dst, src...)  \u002F\u002F is legal if dst is nil and\u002For src is nil\ncopy(dst, src)  \u002F\u002F is legal if dst is nil and\u002For src is nil\n(string(src) == \"\")  \u002F\u002F is true if src is nil\n(len(src) == 0)  \u002F\u002F is true if src is nil\nsrc = src[:0]  \u002F\u002F works like a charm with nil src\n\n\u002F\u002F this for loop doesn't panic if src is nil\nfor i, ch := range src {\n\tdoSomething(i, ch)\n}\n```\n\nSo throw away nil checks for `[]byte` buffers from you code. For example,\n\n```go\nsrcLen := 0\nif src != nil {\n\tsrcLen = len(src)\n}\n```\n\nbecomes\n\n```go\nsrcLen := len(src)\n```\n\n- String may be appended to `[]byte` buffer with `append`\n\n```go\ndst = append(dst, \"foobar\"...)\n```\n\n- `[]byte` buffer may be extended to its' capacity.\n\n```go\nbuf := make([]byte, 100)\na := buf[:10]  \u002F\u002F len(a) == 10, cap(a) == 100.\nb := a[:100]  \u002F\u002F is valid, since cap(a) == 100.\n```\n\n- All fasthttp functions accept nil `[]byte` buffer\n\n```go\nstatusCode, body, err := fasthttp.Get(nil, \"http:\u002F\u002Fgoogle.com\u002F\")\nuintBuf := fasthttp.AppendUint(nil, 1234)\n```\n\n- String and `[]byte` buffers may converted without memory allocations\n\n```go\nfunc b2s(b []byte) string {\n    return *(*string)(unsafe.Pointer(&b))\n}\n\nfunc s2b(s string) (b []byte) {\n    bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))\n    sh := (*reflect.StringHeader)(unsafe.Pointer(&s))\n    bh.Data = sh.Data\n    bh.Cap = sh.Len\n    bh.Len = sh.Len\n    return b\n}\n```\n\n### Warning:\n\nThis is an **unsafe** way, the result string and `[]byte` buffer share the same bytes.\n\n**Please make sure not to modify the bytes in the `[]byte` buffer if the string still survives!**\n\n## Related projects\n\n- [fasthttp](https:\u002F\u002Fgithub.com\u002Ffasthttp) - various useful\n  helpers for projects based on fasthttp.\n- [fasthttp-routing](https:\u002F\u002Fgithub.com\u002Fqiangxue\u002Ffasthttp-routing) - fast and\n  powerful routing package for fasthttp servers.\n- [http2](https:\u002F\u002Fgithub.com\u002Fdgrr\u002Fhttp2) - HTTP\u002F2 implementation for fasthttp.\n- [router](https:\u002F\u002Fgithub.com\u002Ffasthttp\u002Frouter) - a high\n  performance fasthttp request router that scales well.\n- [fasthttp-auth](https:\u002F\u002Fgithub.com\u002Fcasbin\u002Ffasthttp-auth) - Authorization middleware for fasthttp using Casbin.\n- [fastws](https:\u002F\u002Fgithub.com\u002Ffasthttp\u002Ffastws) - Bloatless WebSocket package made for fasthttp\n  to handle Read\u002FWrite operations concurrently.\n- [gramework](https:\u002F\u002Fgithub.com\u002Fgramework\u002Fgramework) - a web framework made by one of fasthttp maintainers.\n- [lu](https:\u002F\u002Fgithub.com\u002FvincentLiuxiang\u002Flu) - a high performance\n  go middleware web framework which is based on fasthttp.\n- [websocket](https:\u002F\u002Fgithub.com\u002Ffasthttp\u002Fwebsocket) - Gorilla-based\n  websocket implementation for fasthttp.\n- [websocket](https:\u002F\u002Fgithub.com\u002Fdgrr\u002Fwebsocket) - Event-based high-performance WebSocket library for zero-allocation\n  websocket servers and clients.\n- [fasthttpsession](https:\u002F\u002Fgithub.com\u002Fphachon\u002Ffasthttpsession) - a fast and powerful session package for fasthttp servers.\n- [atreugo](https:\u002F\u002Fgithub.com\u002Fsavsgio\u002Fatreugo) - High performance and extensible micro web framework with zero memory allocations in hot paths.\n- [kratgo](https:\u002F\u002Fgithub.com\u002Fsavsgio\u002Fkratgo) - Simple, lightweight and ultra-fast HTTP Cache to speed up your websites.\n- [kit-plugins](https:\u002F\u002Fgithub.com\u002Fwencan\u002Fkit-plugins\u002Ftree\u002Fmaster\u002Ftransport\u002Ffasthttp) - go-kit transport implementation for fasthttp.\n- [Fiber](https:\u002F\u002Fgithub.com\u002Fgofiber\u002Ffiber) - An Expressjs inspired web framework running on Fasthttp.\n- [Gearbox](https:\u002F\u002Fgithub.com\u002Fgogearbox\u002Fgearbox) - :gear: gearbox is a web framework written in Go with a focus on high performance and memory optimization.\n- [http2curl](https:\u002F\u002Fgithub.com\u002Fli-jin-gou\u002Fhttp2curl) - A tool to convert fasthttp requests to curl command line.\n- [OpenTelemetry Golang Compile Time Instrumentation](https:\u002F\u002Fgithub.com\u002Falibaba\u002Fopentelemetry-go-auto-instrumentation) - A tool to monitor fasthttp application without changing any code with OpenTelemetry APIs.\n- [protoc-gen-httpgo](https:\u002F\u002Fgithub.com\u002FMUlt1mate\u002Fprotoc-gen-httpgo) - A protoc plugin that generates fasthttp server and client code.\n\n## FAQ\n\n- _Why creating yet another http package instead of optimizing net\u002Fhttp?_\n\n  Because net\u002Fhttp API limits many optimization opportunities.\n  For example:\n\n  - net\u002Fhttp Request object lifetime isn't limited by request handler execution\n    time. So the server must create a new request object per each request instead\n    of reusing existing objects like fasthttp does.\n  - net\u002Fhttp headers are stored in a `map[string][]string`. So the server\n    must parse all the headers, convert them from `[]byte` to `string` and put\n    them into the map before calling user-provided request handler.\n    This all requires unnecessary memory allocations avoided by fasthttp.\n  - net\u002Fhttp client API requires creating a new response object per each request.\n\n- _Why fasthttp API is incompatible with net\u002Fhttp?_\n\n  Because net\u002Fhttp API limits many optimization opportunities. See the answer\n  above for more details. Also certain net\u002Fhttp API parts are suboptimal\n  for use:\n\n  - Compare [net\u002Fhttp connection hijacking](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Hijacker)\n    to [fasthttp connection hijacking](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.Hijack).\n  - Compare [net\u002Fhttp Request.Body reading](https:\u002F\u002Fpkg.go.dev\u002Fnet\u002Fhttp#Request)\n    to [fasthttp request body reading](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.PostBody).\n\n- _Why fasthttp doesn't support HTTP\u002F2.0 and WebSockets?_\n\n  [HTTP\u002F2.0 support](https:\u002F\u002Fgithub.com\u002Ffasthttp\u002Fhttp2) is in progress. [WebSockets](https:\u002F\u002Fgithub.com\u002Ffasthttp\u002Fwebsockets) has been done already.\n  Third parties also may use [RequestCtx.Hijack](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.Hijack)\n  for implementing these goodies.\n\n- _Are there known net\u002Fhttp advantages comparing to fasthttp?_\n\n  Yes:\n\n  - net\u002Fhttp supports [HTTP\u002F2.0 starting from go1.6](https:\u002F\u002Fpkg.go.dev\u002Fgolang.org\u002Fx\u002Fnet\u002Fhttp2).\n  - net\u002Fhttp API is stable, while fasthttp API constantly evolves.\n  - net\u002Fhttp handles more HTTP corner cases.\n  - net\u002Fhttp can stream both request and response bodies\n  - net\u002Fhttp can handle bigger bodies as it doesn't read the whole body into memory\n  - net\u002Fhttp should contain less bugs, since it is used and tested by much\n    wider audience.\n\n- _Why fasthttp API prefers returning `[]byte` instead of `string`?_\n\n  Because `[]byte` to `string` conversion isn't free - it requires memory\n  allocation and copy. Feel free wrapping returned `[]byte` result into\n  `string()` if you prefer working with strings instead of byte slices.\n  But be aware that this has non-zero overhead.\n\n- _Which GO versions are supported by fasthttp?_\n\n  We support the same versions the Go team supports.\n  Currently that is Go 1.24.x and newer.\n  Older versions might work, but won't officially be supported.\n\n- _Please provide real benchmark data and server information_\n\n  See [this issue](https:\u002F\u002Fgithub.com\u002Fvalyala\u002Ffasthttp\u002Fissues\u002F4).\n\n- _Are there plans to add request routing to fasthttp?_\n\n  There are no plans to add request routing into fasthttp.\n  Use third-party routers and web frameworks with fasthttp support:\n\n  - [fasthttp-routing](https:\u002F\u002Fgithub.com\u002Fqiangxue\u002Ffasthttp-routing)\n  - [router](https:\u002F\u002Fgithub.com\u002Ffasthttp\u002Frouter)\n  - [gramework](https:\u002F\u002Fgithub.com\u002Fgramework\u002Fgramework)\n  - [lu](https:\u002F\u002Fgithub.com\u002FvincentLiuxiang\u002Flu)\n  - [atreugo](https:\u002F\u002Fgithub.com\u002Fsavsgio\u002Fatreugo)\n  - [Fiber](https:\u002F\u002Fgithub.com\u002Fgofiber\u002Ffiber)\n  - [Gearbox](https:\u002F\u002Fgithub.com\u002Fgogearbox\u002Fgearbox)\n\n- _I detected data race in fasthttp!_\n\n  Cool! [File a bug](https:\u002F\u002Fgithub.com\u002Fvalyala\u002Ffasthttp\u002Fissues\u002Fnew). But before\n  doing this check the following in your code:\n\n  - Make sure there are no references to [RequestCtx](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx)\n    or to its' members after returning from [RequestHandler](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestHandler).\n  - Make sure you call [TimeoutError](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx.TimeoutError)\n    before returning from [RequestHandler](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestHandler)\n    if there are references to [RequestCtx](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fvalyala\u002Ffasthttp#RequestCtx)\n    or to its' members, which may be accessed by other goroutines.\n\n- _I didn't find an answer for my question here_\n\n  Try exploring [these questions](https:\u002F\u002Fgithub.com\u002Fvalyala\u002Ffasthttp\u002Fissues?q=label%3Aquestion).\n","valyala\u002Ffasthttp 是一个专为高性能设计的 Go 语言 HTTP 包。该项目通过优化关键路径上的内存分配，实现了比标准库 net\u002Fhttp 高达 10 倍的速度提升。其核心功能包括高效的请求处理、低延迟响应以及对大量并发连接的支持。fasthttp 特别适用于需要处理每秒数千个中小型请求且要求响应时间稳定在毫秒级别的场景，例如高并发的 Web 服务或 API 网关。尽管它在特定高性能需求下表现出色，但对于大多数常规应用而言，net\u002Fhttp 因其易用性和更广泛的适用性而更为推荐。",2,"2026-06-11 03:00:22","top_language"]