Standard library / net/http
http.ReadRequest()
Parse an HTTP/1.x request from a buffered reader. Expected stdout: 'GET /demo example.invalid\n'.
Formal Syntax & Structure
go syntaxgo
func ReadRequest(b *bufio.Reader) (*Request, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| b | *bufio.Reader | Byte buffer, binary representation or prefix length as indicated by its type. |
Return Value
(*Request, error)
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "bufio" "fmt" "net/http" "strings")
func main() { r := must(http.ReadRequest(bufio.NewReader(strings.NewReader("GET /demo HTTP/1.1\r\nHost: example.invalid\r\n\r\n")))) defer r.Body.Close() fmt.Println(r.Method, r.URL.Path, r.Host)}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}