joellubi commented on code in PR #40284: URL: https://github.com/apache/arrow/pull/40284#discussion_r1508392171
########## go/arrow/flight/session/session.go: ########## @@ -0,0 +1,240 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package session provides server middleware and reference implementations for Flight session management. +// +// For more details on the Flight Session Specification, see: +// https://arrow.apache.org/docs/format/FlightSql.html#flight-server-session-management +// +// [NewServerSessionMiddleware] manages sessions using cookies, so any client would need its own +// middleware/support for storing and sending those cookies. The cookies may be stateful or stateless: +// +// - [NewStatefulServerSessionManager] implements stateful cookies. +// +// - [NewStatelessServerSessionManager] implements stateless cookies. +// +// See details of either implementation for caveats and recommended usage scenarios. +package session + +import ( + "context" + "errors" + "fmt" + "net/http" + "sync" + + "github.com/apache/arrow/go/v16/arrow/flight" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" +) + +var ErrNoSession error = errors.New("flight: server session not present") + +type sessionMiddlewareKey struct{} + +// Return a copy of the provided context containing the provided ServerSession +func NewSessionContext(ctx context.Context, session ServerSession) context.Context { + return context.WithValue(ctx, sessionMiddlewareKey{}, session) +} + +// Retrieve the ServerSession from the provided context if it exists. +// An error indicates that the session was not found in the context. +func GetSessionFromContext(ctx context.Context) (ServerSession, error) { + session, ok := ctx.Value(sessionMiddlewareKey{}).(ServerSession) + if !ok { + return nil, ErrNoSession + } + return session, nil +} + +// Container for named SessionOptionValues Review Comment: Updated -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
