-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests to the handle_error directive
- Loading branch information
1 parent
d8f2270
commit 4f0b4ea
Showing
7 changed files
with
634 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
caddytest/integration/caddyfile_adapt/error_range_codes.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
{ | ||
http_port 3010 | ||
} | ||
localhost:3010 { | ||
root * /srv | ||
error /private* "Unauthorized" 410 | ||
error /hidden* "Not found" 404 | ||
|
||
handle_errors 4xx { | ||
respond "Error in the [400 .. 499] range" | ||
} | ||
} | ||
---------- | ||
{ | ||
"apps": { | ||
"http": { | ||
"http_port": 3010, | ||
"servers": { | ||
"srv0": { | ||
"listen": [ | ||
":3010" | ||
], | ||
"routes": [ | ||
{ | ||
"match": [ | ||
{ | ||
"host": [ | ||
"localhost" | ||
] | ||
} | ||
], | ||
"handle": [ | ||
{ | ||
"handler": "subroute", | ||
"routes": [ | ||
{ | ||
"handle": [ | ||
{ | ||
"handler": "vars", | ||
"root": "/srv" | ||
} | ||
] | ||
}, | ||
{ | ||
"handle": [ | ||
{ | ||
"error": "Unauthorized", | ||
"handler": "error", | ||
"status_code": 410 | ||
} | ||
], | ||
"match": [ | ||
{ | ||
"path": [ | ||
"/private*" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"handle": [ | ||
{ | ||
"error": "Not found", | ||
"handler": "error", | ||
"status_code": 404 | ||
} | ||
], | ||
"match": [ | ||
{ | ||
"path": [ | ||
"/hidden*" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"terminal": true | ||
} | ||
], | ||
"errors": { | ||
"routes": [ | ||
{ | ||
"match": [ | ||
{ | ||
"expression": "{http.error.status_code} \u003e= 400 \u0026\u0026 {http.error.status_code} \u003c= 499" | ||
} | ||
], | ||
"handle": [ | ||
{ | ||
"handler": "subroute", | ||
"routes": [ | ||
{ | ||
"handle": [ | ||
{ | ||
"body": "Error in the [400 .. 499] range", | ||
"handler": "static_response" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"terminal": true | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
156 changes: 156 additions & 0 deletions
156
caddytest/integration/caddyfile_adapt/error_range_simple_codes.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
{ | ||
http_port 2099 | ||
} | ||
localhost:2099 { | ||
root * /srv | ||
error /private* "Unauthorized" 410 | ||
error /threehundred* "Moved Permanently" 301 | ||
error /internalerr* "Internal Server Error" 500 | ||
|
||
handle_errors 500 3xx { | ||
respond "Error code is equal to 500 or in the [300..399] range" | ||
} | ||
handle_errors 4xx { | ||
respond "Error in the [400 .. 499] range" | ||
} | ||
} | ||
---------- | ||
{ | ||
"apps": { | ||
"http": { | ||
"http_port": 2099, | ||
"servers": { | ||
"srv0": { | ||
"listen": [ | ||
":2099" | ||
], | ||
"routes": [ | ||
{ | ||
"match": [ | ||
{ | ||
"host": [ | ||
"localhost" | ||
] | ||
} | ||
], | ||
"handle": [ | ||
{ | ||
"handler": "subroute", | ||
"routes": [ | ||
{ | ||
"handle": [ | ||
{ | ||
"handler": "vars", | ||
"root": "/srv" | ||
} | ||
] | ||
}, | ||
{ | ||
"handle": [ | ||
{ | ||
"error": "Moved Permanently", | ||
"handler": "error", | ||
"status_code": 301 | ||
} | ||
], | ||
"match": [ | ||
{ | ||
"path": [ | ||
"/threehundred*" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"handle": [ | ||
{ | ||
"error": "Internal Server Error", | ||
"handler": "error", | ||
"status_code": 500 | ||
} | ||
], | ||
"match": [ | ||
{ | ||
"path": [ | ||
"/internalerr*" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"handle": [ | ||
{ | ||
"error": "Unauthorized", | ||
"handler": "error", | ||
"status_code": 410 | ||
} | ||
], | ||
"match": [ | ||
{ | ||
"path": [ | ||
"/private*" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"terminal": true | ||
} | ||
], | ||
"errors": { | ||
"routes": [ | ||
{ | ||
"match": [ | ||
{ | ||
"expression": "{http.error.status_code} \u003e= 400 \u0026\u0026 {http.error.status_code} \u003c= 499" | ||
} | ||
], | ||
"handle": [ | ||
{ | ||
"handler": "subroute", | ||
"routes": [ | ||
{ | ||
"handle": [ | ||
{ | ||
"body": "Error in the [400 .. 499] range", | ||
"handler": "static_response" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"terminal": true | ||
}, | ||
{ | ||
"match": [ | ||
{ | ||
"expression": "{http.error.status_code} \u003e= 300 \u0026\u0026 {http.error.status_code} \u003c= 399 || {http.error.status_code} in [500]" | ||
} | ||
], | ||
"handle": [ | ||
{ | ||
"handler": "subroute", | ||
"routes": [ | ||
{ | ||
"handle": [ | ||
{ | ||
"body": "Error code is equal to 500 or in the [300..399] range", | ||
"handler": "static_response" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"terminal": true | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.