]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Use content-disposition to set a filename to be used when downloading recorded files
authorAndreas Öman <andreas@lonelycoder.com>
Wed, 2 Mar 2011 22:47:57 +0000 (23:47 +0100)
committerAndreas Öman <andreas@lonelycoder.com>
Wed, 2 Mar 2011 22:47:57 +0000 (23:47 +0100)
src/http.c
src/http.h
src/webui/webui.c

index 8d94c8bc6648d7dfb2ab32cdf2a849849afcca5d..694f56aeea1f80bdbdc84dcb69e820b4958fb805 100644 (file)
@@ -152,7 +152,8 @@ void
 http_send_header(http_connection_t *hc, int rc, const char *content, 
                 int64_t contentlen,
                 const char *encoding, const char *location, 
-                int maxage, const char *range)
+                int maxage, const char *range,
+                const char *disposition)
 {
   struct tm tm0, *tm;
   htsbuf_queue_t hdrs;
@@ -212,6 +213,9 @@ http_send_header(http_connection_t *hc, int rc, const char *content,
     htsbuf_qprintf(&hdrs, "Accept-Ranges: %s\r\n", "bytes");
     htsbuf_qprintf(&hdrs, "Content-Range: %s\r\n", range);
   }
+
+  if(disposition != NULL)
+    htsbuf_qprintf(&hdrs, "Content-Disposition: %s\r\n", disposition);
   
   htsbuf_qprintf(&hdrs, "\r\n");
 
@@ -228,7 +232,7 @@ http_send_reply(http_connection_t *hc, int rc, const char *content,
                const char *encoding, const char *location, int maxage)
 {
   http_send_header(hc, rc, content, hc->hc_reply.hq_size,
-                  encoding, location, maxage, 0);
+                  encoding, location, maxage, 0, NULL);
   
   if(hc->hc_no_output)
     return;
index 86adf1b0e74834d1cead033fb8e020f2e4792cfa..2a29b8a9fbaa66c9b074100cbc9cf397dfe5a32a 100644 (file)
@@ -113,7 +113,8 @@ void http_redirect(http_connection_t *hc, const char *location);
 
 void http_send_header(http_connection_t *hc, int rc, const char *content, 
                      int64_t contentlen, const char *encoding,
-                     const char *location, int maxage, const char *range);
+                     const char *location, int maxage, const char *range,
+                     const char *disposition);
 
 typedef int (http_callback_t)(http_connection_t *hc, 
                              const char *remain, void *opaque);
index 6c721ac69dc1688e067d509fe79369b0acc79324..7a696652a0eb6e45485e212a6c106cc263512cc6 100644 (file)
@@ -115,7 +115,7 @@ page_static_file(http_connection_t *hc, const char *remain, void *opaque)
     return 404;
   }
 
-  http_send_header(hc, 200, content, st.st_size, NULL, NULL, 10, 0);
+  http_send_header(hc, 200, content, st.st_size, NULL, NULL, 10, 0, NULL);
   sendfile(hc->hc_fd, fd, NULL, st.st_size);
   close(fd);
   return 0;
@@ -503,7 +503,8 @@ page_static_bundle(http_connection_t *hc, const char *remain, void *opaque)
     if(!strcmp(fbe->filename, remain)) {
 
       http_send_header(hc, 200, content, fbe->size, 
-                      fbe->original_size == -1 ? NULL : "gzip", NULL, 10, 0);
+                      fbe->original_size == -1 ? NULL : "gzip", NULL, 10, 0,
+                      NULL);
       /* ignore return value */
       n = write(hc->hc_fd, fbe->data, fbe->size);
       return 0;
@@ -519,12 +520,13 @@ page_static_bundle(http_connection_t *hc, const char *remain, void *opaque)
 static int
 page_dvrfile(http_connection_t *hc, const char *remain, void *opaque)
 {
-  int fd;
+  int fd, i;
   struct stat st;
   const char *content = NULL, *postfix, *range;
   dvr_entry_t *de;
   char *fname;
   char range_buf[255];
+  char disposition[256];
   off_t content_len, file_start, file_end, chunk;
   ssize_t r;
   
@@ -584,9 +586,24 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque)
   if(file_start > 0)
     lseek(fd, file_start, SEEK_SET);
 
+  if(de->de_title != NULL) {
+    snprintf(disposition, sizeof(disposition),
+            "attachment; filename=%s.mkv", de->de_title);
+    i = 20;
+    while(disposition[i]) {
+      if(disposition[i] == ' ')
+       disposition[i] = '_';
+      i++;
+    }
+    
+  } else {
+    disposition[0] = 0;
+  }
+
   http_send_header(hc, range ? HTTP_STATUS_PARTIAL_CONTENT : HTTP_STATUS_OK,
                   content, content_len, NULL, NULL, 10, 
-                  range ? range_buf : NULL);
+                  range ? range_buf : NULL,
+                  disposition[0] ? disposition : NULL);
 
   if(!hc->hc_no_output) {
     while(content_len > 0) {