{"record":{"id":"610b970052c7f861","repo":"tursodatabase/turso","slug":"invalid-sync-http-header-header-name","errorCode":null,"errorMessage":"Invalid sync HTTP header: {header.Name}","messagePattern":"Invalid sync HTTP header: (.+?)","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoSyncDatabase.cs","lineNumber":605,"sourceCode":"        var baseUri = request.Url is null ? _remoteUri : NormalizeRemoteUri(new Uri(request.Url, UriKind.Absolute));\n        var requestUri = CombineUri(baseUri, request.Path);\n        ValidateAuthTransport(requestUri, _remoteUri, _options.AuthToken);\n        _lastTransportContext = new SyncTransportContext(\n            request.Method,\n            requestUri,\n            StatusCode: null);\n\n        using var message = new HttpRequestMessage(new HttpMethod(request.Method), requestUri);\n        if (request.Body.Length > 0)\n            message.Content = new ByteArrayContent(request.Body);\n        foreach (var header in request.Headers)\n        {\n            if (message.Headers.TryAddWithoutValidation(header.Name, header.Value))\n                continue;\n\n            message.Content ??= new ByteArrayContent([]);\n            if (!message.Content.Headers.TryAddWithoutValidation(header.Name, header.Value))\n                throw new InvalidOperationException($\"Invalid sync HTTP header: {header.Name}\");\n        }\n        if (!string.IsNullOrWhiteSpace(_options.AuthToken))\n            message.Headers.Authorization = new AuthenticationHeaderValue(\"Bearer\", _options.AuthToken);\n\n        using var response = await _httpClient\n            .SendAsync(message, HttpCompletionOption.ResponseHeadersRead, cancellationToken)\n            .ConfigureAwait(false);\n        _lastTransportContext = _lastTransportContext with\n        {\n            StatusCode = response.StatusCode,\n        };\n        TursoSyncBindings.SetIoStatus(item, (int)response.StatusCode);\n\n        await using var responseStream = await response.Content\n            .ReadAsStreamAsync(cancellationToken)\n            .ConfigureAwait(false);\n        var buffer = ArrayPool<byte>.Shared.Rent(IoBufferSize);\n        try","sourceCodeStart":587,"sourceCodeEnd":623,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data/TursoSyncDatabase.cs#L587-L623","documentation":"When building the HTTP request for sync I/O, headers returned by the native sync engine are added to the HttpRequestMessage; if a header cannot be added to the request or its content (even with TryAddWithoutValidation, which skips validation but still rejects malformed names/characters), HandleHttpCoreAsync throws InvalidOperationException naming the offending header.","triggerScenarios":"A sync HTTP exchange where the native layer supplies a header with an invalid name or characters (e.g. newlines, non-ASCII, forbidden header name conflicts) that both message.Headers.TryAddWithoutValidation and message.Content.Headers.TryAddWithoutValidation reject.","commonSituations":"Custom or unusual Auth Token / header configuration propagated from the native sync options; a native library version emitting headers outside what System.Net.Http allows; control characters accidentally included in configured values.","solutions":["Check the configured options (AuthToken and any custom headers) for illegal characters such as CR/LF or non-ASCII, and clean them.","Upgrade Turso.Data so the header set emitted by the native sync core matches what HttpClient accepts.","If you control the header source, rename/encode the header to a valid HTTP header name per RFC 7230."],"exampleFix":"// before\noptions.AuthToken = token + \"\\n\"; // stray newline from config\n// after\noptions.AuthToken = token.Trim();","handlingStrategy":"validation","validationCode":"static void ValidateHttpHeader(string name, string value)\n{\n    if (string.IsNullOrWhiteSpace(name) || name.Any(c => c < 33 || c > 126))\n        throw new ArgumentException($\"Invalid sync HTTP header name: {name}\");\n    if (value.Contains('\\r') || value.Contains('\\n'))\n        throw new ArgumentException(\"Header value contains line breaks.\");\n}","typeGuard":"static bool IsValidHeader(string name, string value) =>\n    !string.IsNullOrWhiteSpace(name) &&\n    name.All(c => c > 32 && c < 127) &&\n    !value.Contains('\\r') && !value.Contains('\\n');","tryCatchPattern":null,"preventionTips":["Trim AuthToken and any custom header values read from config/env (strip stray newlines).","Use only RFC 7230-compliant header names in sync options.","Validate header configuration at startup before first sync."],"tags":["dotnet","sync","http","headers"],"backgroundTag":"invalid-http-header","analyzedSha":"6c7252267988c76e632af00a671e4b9788dfae13","analyzedAt":"2026-08-31T11:17:35.598Z","contentChangedAt":"2026-08-31T11:17:35.598Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}