Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filetype: caddy is misinterpreting epub as zip #3959

Closed
ghost opened this issue Jan 8, 2021 · 11 comments
Closed

filetype: caddy is misinterpreting epub as zip #3959

ghost opened this issue Jan 8, 2021 · 11 comments

Comments

@ghost
Copy link

ghost commented Jan 8, 2021

When i ran a caddy file-server (with directory listing enabled) on my android device and visit the webpage from another android device and downloaded an epub, the file extention of epub was changed to zip.

edit: it also happens on localhost

@mholt
Copy link
Member

mholt commented Jan 8, 2021

Thanks for opening an issue! We'll look into this.

It's not immediately clear to me what is going on, so I'll need your help to understand it better.

Ideally, we need to be able to reproduce the bug in the most minimal way possible. This allows us to write regression tests to verify the fix is working. If we can't reproduce it, then you'll have to test our changes for us until it's fixed -- and then we can't add test cases, either.

I've attached a template below that will help make this easier and faster! This will require some effort on your part -- please understand that we will be dedicating time to fix the bug you are reporting if you can just help us understand it and reproduce it easily.

This template will ask for some information you've already provided; that's OK, just fill it out the best you can. 👍 I've also included some helpful tips below the template. Feel free to let me know if you have any questions!

Thank you again for your report, we look forward to resolving it!

Template

## 1. Environment

### 1a. Operating system and version

```
paste here
```


### 1b. Caddy version (run `caddy version` or paste commit SHA)

```
paste here
```


### 1c. Go version (if building Caddy from source; run `go version`)

```
paste here
```


## 2. Description

### 2a. What happens (briefly explain what is wrong)




### 2b. Why it's a bug (if it's not obvious)




### 2c. Log output

```
paste terminal output or logs here
```



### 2d. Workaround(s)




### 2e. Relevant links




## 3. Tutorial (minimal steps to reproduce the bug)




Instructions -- please heed otherwise we cannot help you (help us help you!)

  1. Environment: Please fill out your OS and Caddy versions, even if you don't think they are relevant. (They are always relevant.) If you built Caddy from source, provide the commit SHA and specify your exact Go version.

  2. Description: Describe at a high level what the bug is. What happens? Why is it a bug? Not all bugs are obvious, so convince readers that it's actually a bug.

    • 2c) Log output: Paste terminal output and/or complete logs in a code block. DO NOT REDACT INFORMATION except for credentials.
    • 2d) Workaround: What are you doing to work around the problem in the meantime? This can help others who encounter the same problem, until we implement a fix.
    • 2e) Relevant links: Please link to any related issues, pull requests, docs, and/or discussion. This can add crucial context to your report.
  3. Tutorial: What are the minimum required specific steps someone needs to take in order to experience the same bug? Your goal here is to make sure that anyone else can have the same experience with the bug as you do. You are writing a tutorial, so make sure to carry it out yourself before posting it. Please:

    • Start with an empty config. Add only the lines/parameters that are absolutely required to reproduce the bug.
    • Do not run Caddy inside containers.
    • Run Caddy manually in your terminal; do not use systemd or other init systems.
    • If making HTTP requests, avoid web browsers. Use a simpler HTTP client instead, like curl.
    • Do not redact any information from your config (except credentials). Domain names are public knowledge and often necessary for quick resolution of an issue!
    • Note that ignoring this advice may result in delays, or even in your issue being closed. 😞 Only actionable issues are kept open, and if there is not enough information or clarity to reproduce the bug, then the report is not actionable.

Example of a tutorial:

Create a config file:
{ ... }

Open terminal and run Caddy:

$ caddy ...

Make an HTTP request:

$ curl ...

Notice that the result is ___ but it should be ___.

@mholt mholt added the needs info 📭 Requires more information label Jan 8, 2021
@ghost
Copy link
Author

ghost commented Jan 8, 2021

1. Environment

1a. Operating system and version

# uname -a 
Linux localhost 3.18.35+ #2 SMP PREEMPT Fri Mar 8 14:28:56 CST 2019 armv7 Android 

1b. Caddy version (run caddy version or paste commit SHA)

(devel)

1c. Go version (if building Caddy from source; run go version)

paste here

2. Description

2a. What happens (briefly explain what is wrong)

I downloaded an epub form an http fileserver run by caddy, but the epub's .epub extention was substituted by .zip

Caddy is treating epub as zip. Even though an epub is a zip archive it has a dedicated mime type.

2b. Why it's a bug (if it's not obvious)

2c. Log output

paste terminal output or logs here

There is no log output except initial start up log

2d. Workaround(s)

2e. Relevant links

3. Tutorial (minimal steps to reproduce the bug)

  • run caddy fileserver -listen :8080 -browse -root /sdcard on Termux
  • visit localhost:8080
  • go to a directory which has an epub file and download it
  • the downloaed epub will get .zip extention in place on .epub

@mholt
Copy link
Member

mholt commented Jan 8, 2021

Hmmm, there must be some mistake -- the template is only about half filled out.

Be sure to enable debug mode, you will get more logs.

Also please provide the problematic epub file.

@francislavoie
Copy link
Member

How are you building Caddy?

What happens if you use curl -v to download the file? What do the headers look like?

I have a hunch that this is likely a browser bug rather than a bug with Caddy.

@ghost
Copy link
Author

ghost commented Jan 8, 2021

Also please provide the problematic epub file.

It happens with on every epub i have tried.

@ghost
Copy link
Author

ghost commented Jan 8, 2021

How are you building Caddy?

I am not. I got it from the Termux's package manager.

What happens if you use curl -v to download the file? What do the headers look like?

I can't test it now. But darkhttpd worked fine.

@ghost
Copy link
Author

ghost commented Jan 8, 2021

I have a hunch that this is likely a browser bug rather than a bug with Caddy.

It can be. This issue doesn't happen on Chromium on Linux.

@mholt
Copy link
Member

mholt commented Jan 8, 2021

Ok. Considering epub is actually just a zip file (has the same header), the Go standard library is auto-detecting it as a zip file to set the Content-Type header. Your browser is then initiating a download and adding the .zip extension. You can avoid this multiple ways:

  • The Go standard lib reads your system's mime.types file to associate file extensions with MIME types. Make sure epub is in there.
  • Set the Content-Type header yourself
  • Use curl as we asked, instead of a web browser, which tend to do funky things.

This isn't an issue with Caddy, so I'll close it now.

@mholt mholt closed this as completed Jan 8, 2021
@mholt mholt removed the needs info 📭 Requires more information label Jan 8, 2021
@ghost
Copy link
Author

ghost commented Jan 8, 2021

I am now middle of no where, who should i blame - myself, go, chromium on android.

@ghost
Copy link
Author

ghost commented Jan 8, 2021

Considering epub is actually just a zip file (has the same header), the Go standard library is auto-detecting it as a zip file to set the Content-Type header.

But this issue doesn't occur on chromium on linux.

@mholt
Copy link
Member

mholt commented Jan 8, 2021

But this issue doesn't occur on chromium on linux.

That's probably because your Linux system's mime.types file has an epub entry.

If it were a Caddy bug, something like this would be behaving the same on all platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants