Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions gateway/src/shard/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,11 @@ impl Shard {
/// [`shutdown_resumable`]: Self::shutdown_resumable
/// [`shutdown`]: Self::shutdown
pub async fn start(&self) -> Result<(), ShardStartError> {
let url = if let Some(u) = self.0.config.gateway_url.clone() {
u.into_string()
let url = if let Some(u) = &self.0.config.gateway_url {
u.to_string()
} else {
// By making an authenticated gateway information retrieval request
// we're also validating the configured token.
self.0
.config
.http_client()
Expand Down
42 changes: 24 additions & 18 deletions gateway/src/shard/processor/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ impl ShardProcessor {
let properties = IdentifyProperties::new("twilight.rs", "twilight.rs", OS, "", "");

url.push_str("?v=8");

// Discord's documentation states:
//
// "Generally, it is a good idea to explicitly pass the gateway version
// and encoding".
//
// <https://discord.com/developers/docs/topics/gateway#connecting-gateway-url-query-string-params>
url.push_str("&encoding=json");

compression::add_url_feature(&mut url);

emitter.event(Event::ShardConnecting(Connecting {
Expand Down Expand Up @@ -346,29 +355,26 @@ impl ShardProcessor {

pub async fn run(mut self) {
loop {
match self.next_payload().await {
Ok(v) => v,
Err(source) => {
#[cfg(feature = "tracing")]
tracing::warn!("{}", source);

self.emit_disconnected(None, None).await;
if let Err(source) = self.next_payload().await {
#[cfg(feature = "tracing")]
tracing::warn!("{}", source);

if source.fatal() {
break;
}
self.emit_disconnected(None, None).await;

if source.reconnectable() {
self.reconnect().await;
}
if source.fatal() {
break;
}

if source.resumable() {
self.resume().await;
}
if source.reconnectable() {
self.reconnect().await;
}

continue;
if source.resumable() {
self.resume().await;
}
};

continue;
}

if let Err(source) = self.process().await {
#[cfg(feature = "tracing")]
Expand Down
9 changes: 5 additions & 4 deletions http/src/response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use std::{
error::Error,
fmt::{Display, Formatter, Result as FmtResult},
future::Future,
iter::{self, FusedIterator},
iter::FusedIterator,
marker::PhantomData,
pin::Pin,
task::{Context, Poll},
Expand Down Expand Up @@ -242,9 +242,10 @@ impl<T> Response<T> {

// Create a buffer filled with zeroes so we can copy the aggregate
// body into it.
let mut buf = iter::repeat(0)
.take(aggregate.remaining())
.collect::<Vec<_>>();
//
// Using `vec!` is the fastest way to do this, despite it being a
// macro and having unsafe internals.
let mut buf = vec![0; aggregate.remaining()];
aggregate.copy_to_slice(&mut buf);

Ok(buf)
Expand Down