Skip to content

fix: add missing user-agent header to WebSocket handshake requests#133

Merged
lukeocodes merged 1 commit intodeepgram:mainfrom
brian-contio-ai:bug/add-user-agent-to-ws-requests
Feb 26, 2026
Merged

fix: add missing user-agent header to WebSocket handshake requests#133
lukeocodes merged 1 commit intodeepgram:mainfrom
brian-contio-ai:bug/add-user-agent-to-ws-requests

Conversation

@brian-contio-ai
Copy link
Copy Markdown
Contributor

fix: add missing user-agent header to WebSocket handshake requests

  • Add user-agent header to WebSocket upgrade requests in websocket.rs and flux.rs
  • Ensures consistent user-agent across all HTTP/WebSocket requests
  • Fixes AWS WAF "NoUserAgent_Header" rule violations

Proposed changes

This PR is first - amazing, because it is so minimal. But second, awesome, because it helps keep the code DRY and consistent. There exists standard cloud environments that block all traffic to APIs if you don't have a user agent. Right now the Deepgram SDK for Rust doesn't always set a USER AGENT on its requests. This ensures that we always have a USER AGENT set in the HTTP headers so that the traffic won't get blocked by it. It's also just good practice and good hygiene to set this regardless. I classified this as a bug because for a standard out of the box AWS WAF in front of an AWS LB in front of an auto-scaling group of EC2 instances running the default Deepgram Docker images will break and not work without having a USER AGENT on each request made to it. Specifically AWS WAF has a "NoUserAgent_Header" rule that will block traffic from this SDK.

Not a breaking change, not a new feature, and very minimal change.

Types of changes

  • 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

  • I have read the CONTRIBUTING.md doc
  • I have added tests and/or examples that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

No new tests were added since this is a simple refactoring that moves an existing
constant to make it accessible to WebSocket modules. The existing tests continue
to validate the overall functionality.

Further comments

Alternatives include just disabling the NoUserAgent_Header, but we've seen several bots hit various endpoints and blocking any requests that do not have a header has been a good practice and is part of AWS's best practices.

One last note! The CONTRIBUTING.MD file mentions to open a PR against the dev branch. But there isn't one, so I am opening against main. If this is a mistake, please let me know and I will change it.

- Add user-agent header to WebSocket upgrade requests in websocket.rs and flux.rs
- Ensures consistent user-agent across all HTTP/WebSocket requests
- Fixes AWS WAF "NoUserAgent_Header" rule violations
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ensures WebSocket handshake (upgrade) requests include a User-Agent header, aligning them with the existing reqwest HTTP client behavior and preventing AWS WAF NoUserAgent_Header rule violations.

Changes:

  • Promotes the existing USER_AGENT string to a crate-level pub(crate) static in src/lib.rs.
  • Adds user-agent: crate::USER_AGENT to the WebSocket upgrade request builders in both websocket.rs and flux.rs.
  • Keeps the existing reqwest::ClientBuilder::user_agent(USER_AGENT) behavior unchanged while reusing the same value for WebSockets.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/lib.rs Moves USER_AGENT to crate scope so it can be reused across HTTP and WebSocket codepaths.
src/listen/websocket.rs Adds user-agent header to the live transcription WebSocket handshake request.
src/listen/flux.rs Adds user-agent header to the Flux WebSocket handshake request.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lukeocodes lukeocodes merged commit 62e54d8 into deepgram:main Feb 26, 2026
13 checks passed
@lukeocodes lukeocodes mentioned this pull request Feb 26, 2026
5 tasks
lukeocodes added a commit that referenced this pull request Feb 26, 2026
## Summary

- **fix**: `Container::None` serialization typo (`"nonne"` → `"none"`)
causing 400 errors on TTS raw audio requests (#122)
- **fix**: missing `User-Agent` header on WebSocket handshake requests,
breaking AWS WAF compatibility (#133)
- **fix**: broken Discord badge in README (#135)
- **fix**: Flux WebSocket now handles unknown message types gracefully
instead of producing stream-breaking `JsonError`s (#141)
- `FluxResponse::Unknown(serde_json::Value)` preserves the raw JSON for
inspection/logging
- `TurnEvent::Unknown` catches unrecognized event strings via
`#[serde(other)]`
  - Non-breaking: both enums are `#[non_exhaustive]`

## Changes

- Bump version to 0.9.1
- Update CHANGELOG with 0.9.1 entries
- Lock 0.9.0 changelog link to `0.9.0` tag

## Test plan

- [x] Verified `Container::None` serialization bug with unit test and
e2e against Deepgram API
- [x] Confirmed fix produces `container=none` and API returns audio
successfully
- [x] Mock WebSocket tests verify unknown messages don't break the Flux
stream
- [x] E2e test streams real audio to Deepgram Flux API successfully
- [x] CI passes on this branch
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.

3 participants