Commit 3cd6e937fc2051bae48689eb7da8155d27eda85d

Authored by totoro
1 parent f9a8f3a8

add filename (content-disposition) in headers_for_send_file

search for correct MIME type for sending file
Showing 1 changed file with 22 additions and 17 deletions   Show diff stats
web/CXM_multihost_http_server.anubis
@@ -2146,25 +2146,28 @@ public define String @@ -2146,25 +2146,28 @@ public define String
2146 We send 2 headers 'Content-Type' and 'Content-Length'. 2146 We send 2 headers 'Content-Type' and 'Content-Length'.
2147 2147
2148 define List(HTTP_header) 2148 define List(HTTP_header)
2149 - headers_for_send_file  
2150 - (  
2151 - MIME mime_type,  
2152 - Int size,  
2153 - String etag,  
2154 - Maybe(FileTimes) mb_ftimes,  
2155 - ) =  
2156 - with headers = (List(HTTP_header)) 2149 + headers_for_send_file
  2150 + (
  2151 + MIME mime_type,
  2152 + String filename,
  2153 + Int size,
  2154 + String etag,
  2155 + Maybe(FileTimes) mb_ftimes,
  2156 + )=
  2157 + with headers = (List(HTTP_header))
2157 [ 2158 [
2158 http_header("Content-Type", to_String(mime_type)), 2159 http_header("Content-Type", to_String(mime_type)),
2159 http_header("Etag", "\""+etag+"\""), 2160 http_header("Etag", "\""+etag+"\""),
2160 http_header("Content-Length",to_decimal(size)), 2161 http_header("Content-Length",to_decimal(size)),
  2162 + http_header("Content-Disposition", "attachment; filename=\"" + filename +"\"")
  2163 +
2161 ], 2164 ],
2162 if mb_ftimes is 2165 if mb_ftimes is
2163 { 2166 {
2164 failure then headers, 2167 failure then headers,
2165 success(ftimes) then [http_header("Last-Modified", format_http_date(to_Int(ftimes.last_modified))) . headers] 2168 success(ftimes) then [http_header("Last-Modified", format_http_date(to_Int(ftimes.last_modified))) . headers]
2166 } 2169 }
2167 - . 2170 +.
2168 2171
2169 2172
2170 2173
@@ -2249,7 +2252,7 @@ define One @@ -2249,7 +2252,7 @@ define One
2249 { 2252 {
2250 false then 2253 false then
2251 forget(reliable_write(connection,to_byte_array("HTTP/1.1 200 OK"+crlf))); 2254 forget(reliable_write(connection,to_byte_array("HTTP/1.1 200 OK"+crlf)));
2252 - forget(reliable_write(connection,[format_headers(headers + headers_for_send_file(mime_type, size, current_etag, mb_ftimes)) , crlf])); 2255 + forget(reliable_write(connection,[format_headers(headers + headers_for_send_file(mime_type, filename, size, current_etag, mb_ftimes)) , crlf]));
2253 //forget(copy_file_to_Connection(file, connection, size)), 2256 //forget(copy_file_to_Connection(file, connection, size)),
2254 send_file_body(desc,connection,file,size,0,filename), 2257 send_file_body(desc,connection,file,size,0,filename),
2255 true then 2258 true then
@@ -2380,19 +2383,21 @@ define One @@ -2380,19 +2383,21 @@ define One
2380 log_journal_msg(desc,"Cannot find file '"+absolute_path+"'.\n"), 2383 log_journal_msg(desc,"Cannot find file '"+absolute_path+"'.\n"),
2381 success(f) then 2384 success(f) then
2382 with size = file_size(f), 2385 with size = file_size(f),
2383 - mime_type = mime("application", "octet-stream", []),  
2384 - 2386 + since split_filename_extension(absolute_path) is (filename, extension),
  2387 + with mime_type = get_MIME_from_extension("."+extension),
  2388 + println("send file answer: "+filename+" ext: "+extension+ " uri :" +uri);
2385 send_file( 2389 send_file(
2386 desc, 2390 desc,
2387 connection, 2391 connection,
2388 input_headers, 2392 input_headers,
2389 output_headers, 2393 output_headers,
2390 size, 2394 size,
2391 - file(f),  
2392 - uri,  
2393 - absolute_path,  
2394 - mime_type,  
2395 - action_before_send_file) 2395 + file(f),
  2396 + filename+"."+extension,
  2397 + absolute_path,
  2398 + mime_type,
  2399 + action_before_send_file
  2400 + )
2396 } 2401 }
2397 . 2402 .
2398 2403