mirror of
https://github.com/caddyserver/website.git
synced 2025-04-25 06:26:17 -04:00
Initial commit
This commit is contained in:
commit
03b6fddeb0
77 changed files with 7599 additions and 0 deletions
47
src/docs/markdown/caddyfile/directives/respond.md
Normal file
47
src/docs/markdown/caddyfile/directives/respond.md
Normal file
|
@ -0,0 +1,47 @@
|
|||
---
|
||||
title: respond (Caddyfile directive)
|
||||
---
|
||||
|
||||
# respond
|
||||
|
||||
Writes a hard-coded/static response to the client.
|
||||
|
||||
|
||||
## Syntax
|
||||
|
||||
```
|
||||
respond [<matcher>] <status>|<body> [<status>] {
|
||||
body <text>
|
||||
close
|
||||
}
|
||||
```
|
||||
|
||||
- **<status>** is the HTTP status code to write. Default 200.
|
||||
- **<body>** is the response body to write.
|
||||
- **body** is an alternate way to provide a body; convenient if it is multiple lines.
|
||||
- **close** will close the client's connection to the server after writing the response.
|
||||
|
||||
To clarify, the first non-matcher argument can be either a 3-digit status code or a response body string. If it is a body, the next argument can be the status code.
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
Write a 200 status with an empty body to all health checks:
|
||||
|
||||
```
|
||||
respond /health-check 200
|
||||
```
|
||||
|
||||
Write a simple response body to all requests:
|
||||
|
||||
```
|
||||
respond "Hello, world!"
|
||||
```
|
||||
|
||||
Write an error response and close the connection:
|
||||
|
||||
```
|
||||
respond /secret/* "Access denied" 403 {
|
||||
close
|
||||
}
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue