patrickhener / goshs

A SimpleHTTPServer written in Go, enhanced with features and with a nice design - https://goshs.de
MIT License
260 stars 22 forks source link

Set modification date on served files #52

Closed aWZHY0yQH81uOYvH closed 1 year ago

aWZHY0yQH81uOYvH commented 1 year ago

In the current version, all files in zip archives have a modification date of 1980.

Also added headers for individually-downloaded files, though browsers seem to ignore it.

patrickhener commented 1 year ago

I tested your version and I tested my version. Both give correct Access-/Modification- and Creation-date. Can you give an example where the downloaded archive will have the wrong date, because I cannot reproduce.

aWZHY0yQH81uOYvH commented 1 year ago
% touch testfile
% ls -l
total 0
-rw-r--r--  1 user  wheel  0 Aug 31 23:48 testfile
% goshs &
INFO   [2023-08-31 23:48:53] Serving on interface lo0 bound to 127.0.0.1:8000 
INFO   [2023-08-31 23:48:53] Serving on interface en0 bound to 192.168.1.50:8000 
INFO   [2023-08-31 23:48:53] Serving HTTP from /tmp/serve                 
INFO   [2023-08-31 23:49:01] [::1]:57657 - [200] - "GET / HTTP/1.1" 

% wget --content-disposition "http://localhost:8000/?file=%252Ftestfile&bulk=true"
--2023-08-31 23:50:54--  http://localhost:8000/?file=%252Ftestfile&bulk=true
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 135 [application/zip]
Saving to: ‘1693551054_goshs_download.zip’

1693551054_goshs_download.zip                                         100%[=======================================================================================================================================================================>]     135  --.-KB/s    in 0s      

2023-08-31 23:50:54 (4.77 MB/s) - ‘1693551054_goshs_download.zip’ saved [135/135]

% unzip -l 1693551054_goshs_download.zip 
Archive:  1693551054_goshs_download.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  00-00-1980 00:00   testfile
---------                     -------
        0                     1 file
% unzip 1693551256_goshs_download.zip 
Archive:  1693551256_goshs_download.zip
replace testfile? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
  inflating: testfile                
% ls -l
total 8
-rw-r--r--  1 user  wheel  135 Aug 31 23:54 1693551256_goshs_download.zip
-rw-r--r--  1 user  wheel    0 Dec 31  1979 testfile

This is on macOS, go version 1.21.0

patrickhener commented 1 year ago

Thanks for clarifying. I can now reproduce in Linux current master version. Thanks for catching this. I will check your version again and if that fixes it I will merge in a minute or two.

patrickhener commented 1 year ago

I will look after the two open issues soon'ish and then release a new version. Thanks again for contributing <3