Store full content-length if using head request to initalize.

This commit is contained in:
SergeantPanda 2025-08-12 17:32:07 -05:00
parent 5eeb51585d
commit 3e16614eab
2 changed files with 28 additions and 1 deletions

View file

@ -93,7 +93,24 @@ class PersistentVODConnection:
# Capture headers from final URL
if not self.content_length:
self.content_length = response.headers.get('content-length')
# First check if we have a pre-stored content length from HEAD request
try:
import redis
r = redis.StrictRedis(host='localhost', port=6379, db=0, decode_responses=True)
content_length_key = f"vod_content_length:{self.session_id}"
stored_length = r.get(content_length_key)
if stored_length:
self.content_length = stored_length
logger.info(f"[{self.session_id}] *** USING PRE-STORED CONTENT LENGTH: {self.content_length} ***")
else:
# Fallback to response headers
self.content_length = response.headers.get('content-length')
logger.info(f"[{self.session_id}] *** USING RESPONSE CONTENT LENGTH: {self.content_length} ***")
except Exception as e:
logger.error(f"[{self.session_id}] Error checking Redis for content length: {e}")
# Fallback to response headers
self.content_length = response.headers.get('content-length')
self.content_type = response.headers.get('content-type', 'video/mp4')
self.final_url = response.url
logger.info(f"[{self.session_id}] *** PERSISTENT CONNECTION - Final URL: {self.final_url} ***")

View file

@ -292,6 +292,16 @@ class VODStreamView(View):
# Close the small range request - we don't need to keep this connection
response.close()
# Store the total content length in Redis for the persistent connection to use
try:
import redis
r = redis.StrictRedis(host='localhost', port=6379, db=0, decode_responses=True)
content_length_key = f"vod_content_length:{session_id}"
r.set(content_length_key, total_size, ex=1800) # Store for 30 minutes
logger.info(f"[VOD-HEAD] Stored total content length {total_size} for session {session_id}")
except Exception as e:
logger.error(f"[VOD-HEAD] Failed to store content length in Redis: {e}")
# Now create a persistent connection for the session (if one doesn't exist)
# This ensures the FUSE GET requests will reuse the same connection
connection_manager = VODConnectionManager.get_instance()