-
-
Notifications
You must be signed in to change notification settings - Fork 98
Description
Describe the Bug
When a file is served with Set-PodeResponseAttachment
or Add-PodeStaticRoute -DownloadOnly
and the file is a symlink, the Content-Length
is that of the symlink, not of the file itself. This causes issues when downloading such files in a browser, like the download hanging when the link size is bigger than the file (see bottom) or the file cutting off (in next section, download the file with Firefox instead of with netcat)
Steps To Reproduce
Steps to reproduce the behavior:
- Create a directory for this test script
- In here, save the following to server.ps1:
Import-Module Pode
Start-PodeServer {
Add-PodeEndpoint -Address * -Port 8080 -Protocol HTTP
Add-PodeStaticRouteGroup -FileBrowser -Routes {
Add-PodeStaticRoute -Path '/' -Source . -DownloadOnly
}
}
- Create a dummy file:
'a'*31 > file
- Create a symlink to it:
ln -s file link
- Now,
ls
the current directory. It should look something like the following. Note the size offile
andlink
.
Directory: .../lengthtest
UnixMode User Group LastWriteTime Size Name
-------- ---- ----- ------------- ---- ----
-rw-r--r-- helpimnotd… helpimnotd… **************** 32 file
lrwxrwxrwx helpimnotd… helpimnotd… **************** 4 link -> file
-rw-r--r-- helpimnotd… helpimnotd… **************** 206 Server.ps1
- Now start the server.
- Use the following
netcat
commands to best see the discrepancy:
file
:
@"
GET /file HTTP/1.1
Host: localhost:8080
"@ | netcat localhost 8080
returns
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Disposition: attachment; filename=file
Content-Length: 32
Date: Mon, 25 Aug 2025 07:45:04 GMT
Server: Pode
X-Pode-ContextId: 8a492f9c-1d1c-1652-f0db-733e016f927e
Connection: close
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
This output is correct since the Content-Length
is 32.
link
:
@"
GET /link HTTP/1.1
Host: localhost:8080
"@ | netcat localhost 8080
returns
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Disposition: attachment; filename=link
Content-Length: 4
Date: Mon, 25 Aug 2025 07:46:10 GMT
Server: Pode
X-Pode-ContextId: dd23214a-19db-4c3f-8b1d-70cd124069a3
Connection: close
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Pode reports the Content-Length
of the link to be 4, but supplies more than that.
Expected Behavior
Pode should correctly report the size of symlinked files
Platform
- OS: Debian 13
Linux 6.12.38+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.38-1 (2025-07-16) x86_64 GNU/Linux
- Browser: Firefox 141.0.3
- Versions:
- Pode: v2.12.1
- PowerShell: 7.5.1
Additional Context
This does not happen when Add-PodeStaticRoute
is not given the -DownloadOnly
parameter.
To hang the download for the timeout period, replace the above steps 3, 4, and 5 with:
3. Create a dummy file:
'a' > file
- Create a symlink to it:
ln -s ./././././././././././././././././././././././file link
- Now,
ls
the current directory. It should look something like the following. Note the size offile
andlink
.
Directory: ~/Shirakami/lengthtest
UnixMode User Group LastWriteTime Size Name
-------- ---- ----- ------------- ---- ----
-rw-r--r-- helpimnotd… helpimnotd… **************** 2 file
lrwxrwxrwx helpimnotd… helpimnotd… **************** 50 link -> ././././././
././././././././././
./././././././file
-rw-r--r-- helpimnotd… helpimnotd… **************** 206 Server.ps1
... and now download link
with Firefox. After it finishes, open the file to see its contents:
a
HTTP/1.1 408 RequestTimeout
Content-Length: 0
Metadata
Metadata
Assignees
Labels
Projects
Status