From b1246311e36c093cc10f0894b60f9a416f53c7e5 Mon Sep 17 00:00:00 2001 From: Ashok Menon Date: Tue, 16 Jul 2024 13:13:09 +0100 Subject: [PATCH] [chore][GraphQL/Limits] Clean up headers (#18662) ## Description Two header related clean-ups: - The version header should no longer be part of the CORS configuration, because we don't expect versions to be configured by (request) header. - The `ShowUsage` type doesn't need to implement `Header` because we only care about comparing its name. ## Test plan CI ## Stack - #18660 - #18661 --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [x] GraphQL: `x-sui-rpc-version` is no longer an accepted request header, as versions are now selected by modifying the path. - [ ] CLI: - [ ] Rust SDK: --- .../src/extensions/query_limits_checker.rs | 17 ++--------------- crates/sui-graphql-rpc/src/server/builder.rs | 10 +++------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/crates/sui-graphql-rpc/src/extensions/query_limits_checker.rs b/crates/sui-graphql-rpc/src/extensions/query_limits_checker.rs index 9f9f731c90880..6159cd8405c8b 100644 --- a/crates/sui-graphql-rpc/src/extensions/query_limits_checker.rs +++ b/crates/sui-graphql-rpc/src/extensions/query_limits_checker.rs @@ -12,9 +12,7 @@ use async_graphql::parser::types::{ }; use async_graphql::{value, Name, Pos, Positioned, Response, ServerResult, Value, Variables}; use async_graphql_value::Value as GqlValue; -use axum::headers; use axum::http::HeaderName; -use axum::http::HeaderValue; use once_cell::sync::Lazy; use std::collections::{BTreeSet, HashMap, VecDeque}; use std::net::SocketAddr; @@ -48,21 +46,10 @@ struct QueryLimitsCheckerExt { pub(crate) const CONNECTION_FIELDS: [&str; 2] = ["edges", "nodes"]; -impl headers::Header for ShowUsage { - fn name() -> &'static HeaderName { +impl ShowUsage { + pub(crate) fn name() -> &'static HeaderName { &LIMITS_HEADER } - - fn decode<'i, I>(_: &mut I) -> Result - where - I: Iterator, - { - Ok(ShowUsage) - } - - fn encode>(&self, _: &mut E) { - unimplemented!() - } } impl ExtensionFactory for QueryLimitsChecker { diff --git a/crates/sui-graphql-rpc/src/server/builder.rs b/crates/sui-graphql-rpc/src/server/builder.rs index f2ef3f408567b..c2429bac1f41d 100644 --- a/crates/sui-graphql-rpc/src/server/builder.rs +++ b/crates/sui-graphql-rpc/src/server/builder.rs @@ -44,7 +44,7 @@ use axum::middleware::{self}; use axum::response::IntoResponse; use axum::routing::{get, post, MethodRouter, Route}; use axum::Extension; -use axum::{headers::Header, Router}; +use axum::Router; use chrono::Utc; use http::{HeaderValue, Method, Request}; use hyper::server::conn::AddrIncoming as HyperAddrIncoming; @@ -57,7 +57,7 @@ use std::net::TcpStream; use std::sync::Arc; use std::time::Duration; use std::{any::Any, net::SocketAddr, time::Instant}; -use sui_graphql_rpc_headers::{LIMITS_HEADER, VERSION_HEADER}; +use sui_graphql_rpc_headers::LIMITS_HEADER; use sui_package_resolver::{PackageStoreWithLruCache, Resolver}; use sui_sdk::SuiClientBuilder; use tokio::join; @@ -309,11 +309,7 @@ impl ServerBuilder { .allow_methods([Method::POST]) // Allow requests from any origin .allow_origin(acl) - .allow_headers([ - hyper::header::CONTENT_TYPE, - VERSION_HEADER.clone(), - LIMITS_HEADER.clone(), - ]); + .allow_headers([hyper::header::CONTENT_TYPE, LIMITS_HEADER.clone()]); Ok(cors) }