@@ -309,6 +309,21 @@ def handle_404(e):
309
309
flight_port = int (os .getenv ('FLIGHT_PORT' , 8815 ))
310
310
path = os .getenv ('DATA' , '.duckdb_data' )
311
311
312
+ def parse_ticket (ticket ):
313
+ try :
314
+ # Try to decode the ticket as a JSON object
315
+ ticket_obj = json .loads (ticket .ticket .decode ("utf-8" ))
316
+ if isinstance (ticket_obj , str ):
317
+ # If the JSON object is a string, parse it again
318
+ ticket_obj = json .loads (ticket_obj )
319
+ if "query" in ticket_obj :
320
+ return ticket_obj ["query" ]
321
+ except (json .JSONDecodeError , AttributeError ):
322
+ # If decoding fails or "query" is not in the object, return the ticket as a string
323
+ return ticket .ticket .decode ("utf-8" )
324
+
325
+
326
+ # Patch the main function where the ticket is processed
312
327
if __name__ == '__main__' :
313
328
# Set up signal handlers
314
329
signal .signal (signal .SIGINT , signal_handler )
@@ -334,12 +349,12 @@ def call_completed(self, exception=None):
334
349
335
350
class HeaderMiddlewareFactory (flight .ServerMiddlewareFactory ):
336
351
def start_call (self , info , headers ):
352
+ logger .debug (f"Info received: { info } " )
337
353
logger .debug (f"Headers received: { headers } " )
338
354
if "authorization" in headers :
339
355
# Get first value from list
340
356
auth = headers ["authorization" ][0 ]
341
357
auth = auth [7 :] if auth .startswith ('Bearer ' ) else auth
342
- logger .info (f"Authorization header found: { auth } " )
343
358
middleware = HeaderMiddleware ()
344
359
middleware .authorization = auth
345
360
return middleware
@@ -425,7 +440,7 @@ def do_get(self, context, ticket):
425
440
except Exception as e :
426
441
logger .debug (f"Middleware access error: { e } " )
427
442
428
- query = ticket . ticket . decode ( "utf-8" )
443
+ query = parse_ticket ( ticket )
429
444
logger .info (f"Executing query: { query } " )
430
445
try :
431
446
result_table = self .conn .execute (query ).fetch_arrow_table ()
0 commit comments