Skip to content

Conversation

jeniya-DG
Copy link

@jeniya-DG jeniya-DG commented Aug 18, 2025

Proposed changes

This PR removes the explicit Content-Length header from Utilities.cs in both the v1 and v2 abstractions.

Types of changes

What types of changes does your code introduce to the community .NET SDK?
Put an x in the boxes that apply

  • [x ] Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update or tests (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • [ x] I have read the CONTRIBUTING doc
  • [ x] I have lint'ed all of my code using repo standards
  • I have added tests that prove my fix is effective or that my feature works

    Not required for this change, as it only removes a redundant header and does not alter existing behavior. Existing tests already cover file upload flows.

  • I have added necessary documentation (if appropriate)

Further comments

No additional tests were added because this is a minimal change.
HttpClient automatically handles Content-Length for StreamContent, so removing this header does not change observable behavior.
All existing tests pass, confirming the SDK continues to function as expected.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of stream uploads by no longer manually setting the Content-Length header. This prevents issues with chunked or unknown-length streams, reducing 400/411 errors and intermittent timeouts. Enhances compatibility with various servers and proxies for both v1 and v2 utilities, leading to more consistent request handling and fewer upload failures.

@jeniya-DG jeniya-DG requested a review from lukeocodes as a code owner August 18, 2025 08:15
Copy link
Contributor

coderabbitai bot commented Aug 18, 2025

Walkthrough

Removed manual "Content-Length" header setting from CreateStreamPayload(Stream body) in Utilities for v1 and v2, leaving StreamContent creation unchanged and relying on default handling for content length.

Changes

Cohort / File(s) Summary
Utilities stream payload header adjustment
Deepgram/Abstractions/v1/Utilities.cs, Deepgram/Abstractions/v2/Utilities.cs
Deleted explicit httpContent.Headers.Add("Content-Length", body.Length.ToString()) in CreateStreamPayload(Stream), retaining StreamContent creation without manual header injection.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 122a175 and 4cc8d43.

📒 Files selected for processing (2)
  • Deepgram/Abstractions/v1/Utilities.cs (0 hunks)
  • Deepgram/Abstractions/v2/Utilities.cs (0 hunks)
💤 Files with no reviewable changes (2)
  • Deepgram/Abstractions/v2/Utilities.cs
  • Deepgram/Abstractions/v1/Utilities.cs
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jeniya-DG
Copy link
Author

The following sample code was used to verify the change with a live WebSocket stream:

// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

using Deepgram.Models.Listen.v2.WebSocket;

namespace SampleApp
{
    class Program
    {
        static async Task Main(string[] args)
        {
            try
            {
                // Initialize Library with default logging
                Library.Initialize();

                // use the client factory with a API Key set with the "DEEPGRAM_API_KEY" environment variable
                var liveClient = new ListenWebSocketClient();

                // Subscribe to the EventResponseReceived event
                await liveClient.Subscribe(new EventHandler<ResultResponse>((sender, e) =>
                {
                    if (e.Channel.Alternatives[0].Transcript == "")
                    {
                        return;
                    }
                    Console.WriteLine($"Speaker: {e.Channel.Alternatives[0].Transcript}");
                }));

                // Start the connection
                var liveSchema = new LiveSchema()
                {
                    Model = "nova-2",
                    Punctuate = true,
                    SmartFormat = true,
                };
                bool bConnected = await liveClient.Connect(liveSchema);
                if (!bConnected)
                {
                    Console.WriteLine("Failed to connect to the server");
                    return;
                }

                // get the webcast data... this is a blocking operation
                try
                {
                    var url = "https://drive.google.com/uc?export=download&id=1GMyga9gpiv1G_ulu4xq1MWg3-WAHU-sf";
                    using (HttpClient client = new HttpClient())
                    {
                        var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
                        Console.WriteLine("Response Headers:");
                        foreach (var header in response.Content.Headers)
                        {
                            Console.WriteLine($"    {header.Key}: {string.Join(", ", header.Value)}");
                        }

                        using (Stream receiveStream = await response.Content.ReadAsStreamAsync())
                        {
                            while (liveClient.IsConnected())
                            {
                                byte[] buffer = new byte[2048];
                                await receiveStream.ReadAsync(buffer, 0, buffer.Length);
                                liveClient.Send(buffer);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                // Stop the connection
                await liveClient.Stop();

                // Teardown Library
                Library.Terminate();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

Observed Behavior:

Before this PR:

Response Headers:
    Content-Type: audio/wav
    Content-Disposition: attachment; filename="redaction_testing.wav"
    Content-Length: 2547662
    Last-Modified: Wed, 20 Aug 2025 20:35:01 GMT
    Expires: Wed, 20 Aug 2025 21:27:23 GMT
    Content-Length: 2547662

After this PR:

Response Headers:
    Content-Type: audio/wav
    Content-Disposition: attachment; filename="redaction_testing.wav"
    Content-Length: 2547662
    Last-Modified: Wed, 20 Aug 2025 20:35:01 GMT
    Expires: Wed, 20 Aug 2025 21:27:23 GMT

Impact:

  • No breaking changes; observable behavior remains the same.
  • All existing tests pass, confirming continued SDK functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant