Revision: 29536
          http://sourceforge.net/p/bibdesk/svn/29536
Author:   hofman
Date:     2025-09-05 17:00:18 +0000 (Fri, 05 Sep 2025)
Log Message:
-----------
get suggested filename from Content-Disposition header of request if available

Modified Paths:
--------------
    trunk/bibdesk/BDSKDownloader.m

Modified: trunk/bibdesk/BDSKDownloader.m
===================================================================
--- trunk/bibdesk/BDSKDownloader.m      2025-09-05 16:49:45 UTC (rev 29535)
+++ trunk/bibdesk/BDSKDownloader.m      2025-09-05 17:00:18 UTC (rev 29536)
@@ -157,6 +157,15 @@
     BDSKDownload *download = [self downloadForTask:task];
     NSString *suggestedFileName = [[task response] suggestedFilename] ?: 
[location lastPathComponent];
     
+    NSString *disposition = [[task originalRequest] 
valueForHTTPHeaderField:@"Content-Disposition"];
+    if ([disposition hasPrefix:@"attachment; filename="]) {
+        disposition = [disposition substringFromIndex:21];
+        if ([disposition hasPrefix:@"\""] && [disposition hasSuffix:@"\""])
+            disposition = [disposition substringWithRange:NSMakeRange(1, 
[disposition length] - 2)];
+        if ([disposition length])
+            suggestedFileName = disposition;
+    }
+    
     [download _decideDestinationWithSuggestedFilename:suggestedFileName 
completionHandler:^(NSURL *destinationURL, BOOL allowOverwrite){
         if (destinationURL == nil) {
             NSError *error = [NSError errorWithDomain:NSURLErrorDomain 
code:NSURLErrorCancelled userInfo:nil];

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to