caddyserver / caddy-docker

Source for the official Caddy v2 Docker Image
https://hub.docker.com/_/caddy
Apache License 2.0
408 stars 74 forks source link

Special characters handled incorrectly when using with Docker Compose #237

Closed Klooven closed 2 years ago

Klooven commented 2 years ago

I'm running the following simple configuration:

compose.yml

services:
  proxy:
    image: caddy:2.5.0-alpine
    restart: unless-stopped
    ports:
      - 80:80
      - 443:443
    volumes:
      - proxy:/data
      - ./Caddyfile:/etc/caddy/Caddyfile

volumes:
  proxy:

Caddyfile

special-chars.klooven.link {
  respond "ääkkösiä"
}

Environment

> docker -v
Docker version 20.10.14, build a224086
> docker compose version
Docker Compose version v2.3.3

The host is running Ubuntu 22.04 LTS


Everything works as expected until this, but when I visit the address I've configured in the Caddyfile, I get the following result:

image

The result I'm expecting to see is obviously:

ääkkösiä

I haven't encountered the issue when running Caddy "natively", but with my Docker Compose setups this has always been an issue. When using the reverse_proxy directive, however, all content served through Caddy render special characters correctly. The only place that seems to have an issue with them is the Caddyfile.


I have yet to determine if this issue originates from the Caddy Docker images or some other part in the process (e.g. the Alpine base image etc.), but I thought that this could be a good place to ask first. I'm happy to share more details if needed, and continue will debugging if anyone has an idea how to resolve the issue.

francislavoie commented 2 years ago

Works for me, on Ubuntu 21.04.

$ docker -v
Docker version 20.10.14, build a224086
$ docker compose version
Docker Compose version v2.3.3

Caddyfile:

{
    debug
}

:8881 {
    respond "ääkkösiä"
}

Run with:

$ docker run --rm -v `pwd`/Caddyfile:/etc/caddy/Caddyfile -p 8881:8881 --name caddy-test caddy:2.5.0-alpine

Test with curl:

$ curl http://localhost:8881
ääkkösiä
francislavoie commented 2 years ago

Ah, I can replicate in a browser. This isn't an issue with Caddy specifically; since there's no Content-Type header, the browser will try to guess the encoding, and probably gets it wrong. If you add a header Content-Type "text/plain; charset=UTF-8" then it works.

{
    debug
}

:8881 {
    header Content-Type "text/plain; charset=UTF-8"
    respond "ääkkösiä"
}
Klooven commented 2 years ago

Ooof...

Tried to set the charset header at one point, checked it now and it seems like I misspelled it 🤦‍♂️ I should maybe take a break 😄

Thanks for the swift response @francislavoie !