Skip to content

Commit

Permalink
[chore][GraphQL/Limits] Clean up headers (#18662)
Browse files Browse the repository at this point in the history
## 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:
  • Loading branch information
amnn authored Jul 16, 2024
1 parent 887812f commit b124631
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
17 changes: 2 additions & 15 deletions crates/sui-graphql-rpc/src/extensions/query_limits_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Self, headers::Error>
where
I: Iterator<Item = &'i HeaderValue>,
{
Ok(ShowUsage)
}

fn encode<E: Extend<HeaderValue>>(&self, _: &mut E) {
unimplemented!()
}
}

impl ExtensionFactory for QueryLimitsChecker {
Expand Down
10 changes: 3 additions & 7 deletions crates/sui-graphql-rpc/src/server/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit b124631

Please sign in to comment.