Skip to content

Commit

Permalink
Set host header based on host URL instead of hardcoding it (#103)
Browse files Browse the repository at this point in the history
* WIP

* Generic solution

* Bump version

* Clippy

* Cargo fmt
  • Loading branch information
RyanChimienti authored Jan 13, 2025
1 parent 958d4fd commit 73e5385
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "deepgram"
version = "0.6.4"
version = "0.6.5"
authors = ["Deepgram <[email protected]>"]
edition = "2021"
description = "Community Rust SDK for Deepgram's automated speech recognition APIs."
Expand Down
6 changes: 4 additions & 2 deletions examples/speak/rest/text_to_speech_to_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ impl Linear16AudioSource {
impl Buf for Linear16AudioSource {
type Sample = i16;

type Channel<'this> = LinearChannel<'this, i16>
type Channel<'this>
= LinearChannel<'this, i16>
where
Self: 'this;

type IterChannels<'this> = std::vec::IntoIter<LinearChannel<'this, i16>>
type IterChannels<'this>
= std::vec::IntoIter<LinearChannel<'this, i16>>
where
Self: 'this;

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> From<&'a Deepgram> for Speak<'a> {
}
}

impl<'a> Transcription<'a> {
impl Transcription<'_> {
/// Expose a method to access the inner `Deepgram` reference if needed.
pub fn deepgram(&self) -> &Deepgram {
self.0
Expand Down
6 changes: 3 additions & 3 deletions src/listen/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ impl Transcription<'_> {
///
/// assert_eq!(&builder.urlencoded().unwrap(), "model=nova-2&detect_language=true&no_delay=true")
/// ```
pub fn stream_request_with_options(&self, options: Options) -> WebsocketBuilder<'_> {
WebsocketBuilder {
deepgram: self.0,
Expand Down Expand Up @@ -166,7 +165,7 @@ impl Transcription<'_> {
}
}

impl<'a> WebsocketBuilder<'a> {
impl WebsocketBuilder<'_> {
/// Return the options in urlencoded format. If serialization would
/// fail, this will also return an error.
///
Expand Down Expand Up @@ -653,13 +652,14 @@ pub struct WebsocketHandle {
impl<'a> WebsocketHandle {
async fn new(builder: WebsocketBuilder<'a>) -> Result<WebsocketHandle> {
let url = builder.as_url()?;
let host = url.host_str().ok_or(DeepgramError::InvalidUrl)?;

let request = {
let http_builder = Request::builder()
.method("GET")
.uri(url.to_string())
.header("sec-websocket-key", client::generate_key())
.header("host", "api.deepgram.com")
.header("host", host)
.header("connection", "upgrade")
.header("upgrade", "websocket")
.header("sec-websocket-version", "13");
Expand Down

0 comments on commit 73e5385

Please sign in to comment.