MCPcopy Create free account
hub / github.com/apache/datafusion / get_ctx

Method get_ctx

datafusion-examples/examples/flight/sql_server.rs:123–146  ·  view source on GitHub ↗
(&self, req: &Request<T>)

Source from the content-addressed store, hash-verified

121 }
122
123 fn get_ctx<T>(&self, req: &Request<T>) -> Result<Arc<SessionContext>, Status> {
124 // get the token from the authorization header on Request
125 let auth = req
126 .metadata()
127 .get("authorization")
128 .ok_or_else(|| Status::internal("No authorization header!"))?;
129 let str = auth
130 .to_str()
131 .map_err(|e| Status::internal(format!("Error parsing header: {e}")))?;
132 let authorization = str.to_string();
133 let bearer = "Bearer ";
134 if !authorization.starts_with(bearer) {
135 Err(Status::internal("Invalid auth header!"))?;
136 }
137 let auth = authorization[bearer.len()..].to_string();
138
139 if let Some(context) = self.contexts.get(&auth) {
140 Ok(context.clone())
141 } else {
142 Err(Status::internal(format!(
143 "Context handle not found: {auth}"
144 )))?
145 }
146 }
147
148 fn get_plan(&self, handle: &str) -> Result<LogicalPlan, Status> {
149 if let Some(plan) = self.statements.get(handle) {

Calls 5

getMethod · 0.45
metadataMethod · 0.45
to_stringMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected