{"record":{"id":"37e36ef34cd9a584","repo":"hyperledger/fabric","slug":"error-creating-http-request","errorCode":null,"errorMessage":"error creating http request","messagePattern":"error creating http request","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go","lineNumber":1595,"sourceCode":"\n\tcouchdbLogger.Debugf(\"Request URL: %s\", requestURL)\n\n\t// attempt the http request for the max number of retries\n\t// if maxRetries is 0, the database creation will be attempted once and will\n\t//    return an error if unsuccessful\n\t// if maxRetries is 3 (default), a maximum of 4 attempts (one attempt with 3 retries)\n\t//    will be made with warning entries for unsuccessful attempts\n\tfor attempts := 0; attempts <= maxRetries; attempts++ {\n\n\t\t// Set up a buffer for the payload data\n\t\tpayloadData := new(bytes.Buffer)\n\n\t\tpayloadData.ReadFrom(bytes.NewReader(data))\n\n\t\t// Create request based on URL for couchdb operation\n\t\treq, err := http.NewRequestWithContext(ctx, method, requestURL.String(), payloadData)\n\t\tif err != nil {\n\t\t\treturn nil, nil, errors.Wrap(err, \"error creating http request\")\n\t\t}\n\n\t\t// set the request to close on completion if shared connections are not allowSharedConnection\n\t\t// Current CouchDB has a problem with zero length attachments, do not allow the connection to be reused.\n\t\t// Apache JIRA item for CouchDB   https://issues.apache.org/jira/browse/COUCHDB-3394\n\t\tif !keepConnectionOpen {\n\t\t\treq.Close = true\n\t\t}\n\n\t\t// add content header for PUT\n\t\tif method == http.MethodPut || method == http.MethodPost || method == http.MethodDelete {\n\n\t\t\t// If the multipartBoundary is not set, then this is a JSON and content-type should be set\n\t\t\t// to application/json.   Else, this is contains an attachment and needs to be multipart\n\t\t\tif multipartBoundary == \"\" {\n\t\t\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t\t\t} else {\n\t\t\t\treq.Header.Set(\"Content-Type\", \"multipart/related;boundary=\\\"\"+multipartBoundary+\"\\\"\")","sourceCodeStart":1577,"sourceCodeEnd":1613,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go#L1577-L1613","documentation":"Returned by handleRequest when http.NewRequestWithContext fails to construct the outgoing HTTP request for the CouchDB operation. This indicates an invalid method, malformed URL, or unusable request body (e.g. nil/invalid reader), not a network failure.","triggerScenarios":"Calling handleRequest with a malformed requestURL (bad characters, unparseable URL), an invalid HTTP method string, or a broken payload reader when attaching large documents/attachments.","commonSituations":"Database or document names containing characters that break URL construction; database names with uppercase letters or invalid characters reaching constructCouchDBUrl; misconfigured CouchDB address with invalid characters.","solutions":["Validate the CouchDB URL in config for illegal characters","Ensure database names are lowercase alphanumeric (no uppercase/spaces), matching CouchDB naming rules","Check any dynamically built path elements (doc IDs, attachment names) for unescaped characters","Log the full requestURL.String() to identify the malformed part"],"exampleFix":"// before\ndbName := \"Ledger1\"\n// after\ndbName := strings.ToLower(dbName)","handlingStrategy":"validation","validationCode":"if _, err := url.Parse(couchAddress); err != nil {\n    return fmt.Errorf(\"invalid couchdb address %q: %w\", couchAddress, err)\n}\nif dbName != strings.ToLower(dbName) { return errors.New(\"dbname must be lowercase\") }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enforce CouchDB lowercase database naming rules in creation code","URL-escape document IDs and attachment names","Validate configured CouchDB URL parses before opening the ledger"],"tags":["http","url","validation","couchdb"],"backgroundTag":"invalid-http-request","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}