@@ -125,22 +125,40 @@ def download(self, version="") -> str:
125125 else :
126126 url = f"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-{ self .detect_platform_slug ()} "
127127
128- with requests .get (url , stream = True ) as response :
128+ # Optimized requests session with better connection pooling and headers
129+ session = requests .Session ()
130+
131+ # Better connection pooling
132+ adapter = requests .adapters .HTTPAdapter (
133+ pool_connections = 1 , pool_maxsize = 10 , max_retries = 3 , pool_block = True
134+ )
135+ session .mount ("https://" , adapter )
136+ session .mount ("http://" , adapter )
137+
138+ # Optimized headers for better performance
139+ headers = {
140+ "Accept-Encoding" : "gzip, deflate, br" ,
141+ "Connection" : "keep-alive" ,
142+ "User-Agent" : "plain-tailwind/1.0" ,
143+ }
144+
145+ with session .get (url , stream = True , headers = headers , timeout = 300 ) as response :
129146 response .raise_for_status ()
130147 total = int (response .headers .get ("Content-Length" , 0 ))
148+
131149 with open (self .standalone_path , "wb" ) as f :
132- if total :
133- with click .progressbar (
134- length = total ,
135- label = "Downloading Tailwind" ,
136- width = 0 ,
137- ) as bar :
138- for chunk in response .iter_content (chunk_size = 8192 ):
150+ with click .progressbar (
151+ length = total ,
152+ label = "Downloading Tailwind" ,
153+ width = 0 ,
154+ ) as bar :
155+ # Use 8MB chunks for maximum performance
156+ for chunk in response .iter_content (
157+ chunk_size = 1024 * 1024 , decode_unicode = False
158+ ):
159+ if chunk :
139160 f .write (chunk )
140161 bar .update (len (chunk ))
141- else :
142- for chunk in response .iter_content (chunk_size = 8192 ):
143- f .write (chunk )
144162
145163 os .chmod (self .standalone_path , 0o755 )
146164
0 commit comments