From 8c896f96e1c04560ce562c8dceb78b73cc6a9730 Mon Sep 17 00:00:00 2001 From: Sunli Date: Thu, 8 Apr 2021 11:41:15 +0800 Subject: [PATCH] Remove spin crate from dependencies --- Cargo.toml | 1 - src/context.rs | 12 +++++++++--- src/schema.rs | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d9c8eb0b..a472fef6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,6 @@ pin-project-lite = "0.2.6" regex = "1.4.5" serde = { version = "1.0.125", features = ["derive"] } serde_json = "1.0.64" -spin = "0.9.0" thiserror = "1.0.24" static_assertions = "1.1.0" http = "0.2.3" diff --git a/src/context.rs b/src/context.rs index 894edced..d2686ffb 100644 --- a/src/context.rs +++ b/src/context.rs @@ -4,7 +4,7 @@ use std::any::{Any, TypeId}; use std::collections::HashMap; use std::fmt::{self, Debug, Display, Formatter}; use std::ops::Deref; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use async_graphql_value::{Value as InputValue, Variables}; use fnv::FnvHashMap; @@ -212,7 +212,7 @@ pub struct QueryEnvInner { pub uploads: Vec, pub session_data: Arc, pub ctx_data: Arc, - pub http_headers: spin::Mutex>, + pub http_headers: Mutex>, pub disable_introspection: bool, } @@ -344,7 +344,11 @@ impl<'a, T> ContextBase<'a, T> { /// } /// ``` pub fn http_header_contains(&self, key: impl AsHeaderName) -> bool { - self.query_env.http_headers.lock().contains_key(key) + self.query_env + .http_headers + .lock() + .unwrap() + .contains_key(key) } /// Sets a HTTP header to response. @@ -395,6 +399,7 @@ impl<'a, T> ContextBase<'a, T> { self.query_env .http_headers .lock() + .unwrap() .insert(name, value.into()) } @@ -434,6 +439,7 @@ impl<'a, T> ContextBase<'a, T> { self.query_env .http_headers .lock() + .unwrap() .append(name, value.into()) } diff --git a/src/schema.rs b/src/schema.rs index c7071c12..7cde9e02 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -476,7 +476,7 @@ where match res { Ok(data) => { let resp = Response::new(data); - resp.http_headers(std::mem::take(&mut *env.http_headers.lock())) + resp.http_headers(std::mem::take(&mut *env.http_headers.lock().unwrap())) } Err(err) => Response::from_errors(vec![err]), }