The respond directive and the close keyword

1. Caddy version (caddy version):

# caddy version
v2.4.3 h1:Y1FaV2N4WO3rBqxSYA8UZsZTQdN+PwcoOcAiZTM8C0I=

2. How I run Caddy:

n/a

a. System environment:

n/a

b. Command:

n/a

c. Service/unit/compose file:

n/a

d. My complete Caddyfile or JSON config:

Code extract

    # External access denied to these files.
    @forbidden {
        not path /wp-includes/ms-files.php
        path /wp-admin/includes*
        path /wp-includes*
        path /wp-config.php
    }
    respond @forbidden "Access denied" 403 {
        close
    }

3. The problem I’m having:

The documentation for respond states the following:

  • close will close the client’s connection to the server after writing the response.

Whether I use the close keyword or not with the respond directive, there’s no visible difference in a browser…

wp15

…so, I’m a little unclear on what the close keyword actually does?

4. Error messages and/or full log output:

n/a

5. What I already tried:

Refer to point 3.

6. Links to relevant resources:

  1. respond

It’s generally not that useful. Closing the connection just means that subsequent requests will require a new TCP connection. It’s a bit more of a “go away now” after writing a response.

1 Like

It is useful sometimes. You might not want to keep a resource around for a client that you don’t particularly need to be serving. We use it for our auto http → https redirects. No point in leaving that connection open on port 80.

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.