siyuan-note/siyuan · error

invalid request:

Error message

invalid request: 

What it means

HTTPRequest builds the actual *http.Request with http.NewRequest after normalizing the method. If that constructor rejects the input (unsupported method token containing invalid characters, unparseable URL at request level, malformed context URL), the error is wrapped as "invalid request: <detail>".

Solutions

  1. Use one of GET/POST/PUT/DELETE/PATCH (or another standard verb) with no extra characters
  2. Inspect the wrapped detail after "invalid request: " to see whether the method or the URL was rejected
  3. Sanitize the method: strings.ToUpper(strings.TrimSpace(method)) and reject strings containing spaces
  4. Validate the URL with http.NewRequest(method, url, nil) in a dry run before the real call

Example fix

// before
HTTPRequest("GET /v1/data", "https://api.example.com", nil, "")
// after
HTTPRequest("GET", "https://api.example.com/v1/data", nil, "")
Defensive patterns

Strategy: validation

Validate before calling

method = strings.ToUpper(strings.TrimSpace(method))
if strings.ContainsAny(method, " \t/") {
    return fmt.Errorf("method %q is not a valid HTTP token", method)
}

Type guard

func isValidHTTPMethod(m string) bool {
    switch strings.ToUpper(strings.TrimSpace(m)) {
    case "GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS":
        return true
    }
    return false
}

Try / catch

if err != nil && strings.HasPrefix(err.Error(), "invalid request: ") {
    detail := strings.TrimPrefix(err.Error(), "invalid request: ")
    return fmt.Errorf("check method/URL inputs: %s", detail)
}

Prevention

When it happens

Trigger: Calling HTTPRequest with a method string containing invalid HTTP token characters (e.g. "GET /extra", "FETCH DATA", method with spaces or non-ASCII) or a URL that url.Parse accepted earlier but http.NewRequest rejects (rare malformed forms).

Common situations: Agent/LLM inventing non-standard HTTP verbs; method strings with trailing whitespace already trimmed but embedded spaces remaining; passing a full request line instead of just the verb; Go version differences in URL validation.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/c3d7c801273db51a. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/httprequest.go:327

		return 0, "", "", errors.New("URL has no host")
	}

	if serr := CheckHostSSRF(u.Hostname()); serr != nil {
		return 0, "", "", serr
	}

	method = strings.ToUpper(strings.TrimSpace(method))
	if method == "" {
		method = "GET"
	}

	var reqBody io.Reader
	if body != "" && method != "GET" && method != "HEAD" {
		reqBody = strings.NewReader(body)
	}
	req, err := http.NewRequest(method, rawURL, reqBody)
	if err != nil {
		return 0, "", "", errors.New("invalid request: " + err.Error())
	}
	for k, v := range headers {
		req.Header.Set(k, v)
	}

	resp, err := ssrfSafeClient.Do(req)
	if err != nil {
		return 0, "", "", errors.New("request failed: " + err.Error())
	}
	if resp == nil {
		return 0, "", "", errors.New("nil response")
	}
	defer resp.Body.Close()

	statusCode = resp.StatusCode
	contentType = resp.Header.Get("Content-Type")

	maxReadBytes := int64(maxHTTPRequestBytes)

View on GitHub (pinned to 9f775e8a12)