AlexxIT/go2rtc · error

wrong request

Error message

wrong request: %s

What it means

ReadRequest parses an incoming RTSP request line and requires exactly three space-separated fields: method, URL, and protocol version. When the line does not split into 3 parts the library reports 'wrong request' instead of constructing a Request. It is the server-side counterpart of the malformed-response check.

Solutions

  1. Inspect the echoed line and fix the client so it sends 'METHOD URL RTSP/1.0' with all three fields.
  2. Reject or skip malformed lines in your accept loop before calling ReadRequest (e.g. peek the line and validate 3 tokens).
  3. Ensure the port is reserved for RTSP — move other protocols or health probes off that listener.
  4. If the line is intentionally non-standard (e.g. 'OPTIONS *'), patch the parser to normalize it to 3 fields before parsing.

Example fix

// before
req, err := conn.ReadRequest()
// after
line := peekLine(conn)
if len(strings.SplitN(line, " ", 3)) != 3 {
	log.Printf("skipping malformed request line: %q", line)
	io.WriteString(conn, "RTSP/1.0 400 Bad Request\r\n\r\n")
	return
}
req, err := conn.ReadRequest()
Defensive patterns

Strategy: validation

Validate before calling

line := peekRequestLine(conn)
if len(strings.SplitN(line, " ", 3)) != 3 {
	io.WriteString(conn, "RTSP/1.0 400 Bad Request\r\n\r\n")
	return
}

Type guard

func isWellFormedRequestLine(line string) bool {
	parts := strings.SplitN(line, " ", 3)
	return len(parts) == 3 && parts[0] != "" && strings.HasPrefix(parts[2], "RTSP/")
}

Try / catch

req, err := conn.ReadRequest()
if err != nil {
	if strings.Contains(err.Error(), "wrong request") {
		io.WriteString(conn, "RTSP/1.0 400 Bad Request\r\n\r\n")
		return
	}
	return err
}

Prevention

When it happens

Trigger: Using ReadResponse/ReadRequest in a server loop when a client sends a request line with wrong field count — e.g. 'OPTIONS *' without RTSP/1.0, a truncated line, or non-RTSP junk like an HTTP probe ('GET / HTTP/1.1' splits fine, but 'HELP' does not).

Common situations: Port scanners or monitoring probes hitting the RTSP server port; clients using an unimplemented or malformed request syntax; tools sending bare methods without URL or protocol version.

Related errors


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/baaf1e2e9edce246. Report an issue: GitHub.

Appendix: source

Thrown at pkg/tcp/textproto.go:122

	return s
}

func (r *Request) Write(w io.Writer) (err error) {
	_, err = w.Write([]byte(r.String()))
	return
}

func ReadRequest(r *bufio.Reader) (*Request, error) {
	tp := textproto.NewReader(r)

	line, err := tp.ReadLine()
	if err != nil {
		return nil, err
	}

	ss := strings.SplitN(line, " ", 3)
	if len(ss) != 3 {
		return nil, fmt.Errorf("wrong request: %s", line)
	}

	req := &Request{
		Method: ss[0],
		Proto:  ss[2],
	}

	req.URL, err = url.Parse(ss[1])
	if err != nil {
		return nil, err
	}

	req.Header, err = tp.ReadMIMEHeader()
	if err != nil {
		return nil, err
	}

	if val := req.Header.Get("Content-Length"); val != "" {

View on GitHub (pinned to c245815e75)