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;
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");
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;
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);
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;
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;
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;
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) {