This repository has been archived on 2021-11-29. You can view files and clone it, but cannot push or open issues or pull requests.
rsstube-bash-old/scripts/http_errors

90 lines
3.1 KiB
Plaintext
Raw Normal View History

2021-11-28 19:00:00 -05:00
cloudflare=""
recaptcha=""
# Cloudflare test
cloudflare=`echo "$content" | grep "<title>Attention Required! | Cloudflare</title>"`
if [[ -n "${cloudflare}" ]]
then
error "Cloudflare blocked the request."
if [[ -n "${proxy}" ]]
then
warn "Are you using Tor? If so, try using rsstube again with the -t option."
fi
fi
# general Google reCAPTCHA
recaptcha=`echo "$content" | grep "google.com/recaptcha/api"`
if [[ -n "${recaptcha}" ]]
then
error "reCAPTCHA requested"
fi
# HTTP errors
http_response=`echo "$content" | head -1 | xargs`
http_response=${http_response#* }
# print appropriate status code
case $http_response in
# 2xx success
200) response_message="200 OK" ;;
# 3xx redirection should already be handled by curl -L flag
301) response_message="301 Moved Permanently" ;;
302) response_message="302 Found" ;;
303) response_message="303 See Other" ;;
307) response_message="307 Temporary Redirect" ;;
308) response_message="308 Permanent Redirect" ;;
# 4xx client errors
400) response_message="400 Bad Request" ;;
401) response_message="401 Unauthorized" ;;
402) response_message="402 Payment Required" ;;
403) response_message="403 Forbidden" ;;
404) response_message="404 Not Found" ;;
405) response_message="405 Method Not Allowed" ;;
406) response_message="406 Not Acceptable" ;;
407) response_message="407 Proxy Authentication Required" ;;
408) response_message="408 Request Timeout" ;;
409) response_message="409 Conflict" ;;
410) response_message="410 Gone" ;;
411) response_message="411 Length Required" ;;
412) response_message="412 Precondition Failed" ;;
413) response_message="413 Payload Too Large" ;;
414) response_message="414 URI Too Long" ;;
415) response_message="415 Unsupported Media Type" ;;
416) response_message="416 Range Not Satisfiable" ;;
417) response_message="417 Expectation Failed" ;;
418) response_message="418 I'm a teapot" ;;
421) response_message="421 Misdirected Request" ;;
422) response_message="422 Unprocessable Entity" ;;
423) response_message="423 Locked" ;;
424) response_message="424 Failed Dependency" ;;
425) response_message="425 Too Early" ;;
426) response_message="426 Upgrade Required" ;;
428) response_message="428 Precondition Required" ;;
429) response_message="429 Too Many Requests" ;;
431) response_message="431 Request Header Fields Too Large" ;;
451) response_message="451 Unavailable For Legal Reasons" ;;
# 5xx server errors
500) response_message="500 Internal Server Error" ;;
501) response_message="501 Not Implemented" ;;
502) response_message="502 Bad Gateway" ;;
503) response_message="503 Service Unavailable" ;;
504) response_message="504 Gateway Timeout" ;;
505) response_message="505 HTTP Version Not Supported" ;;
506) response_message="506 Variant Also Negotiates" ;;
507) response_message="507 Insufficient Storage" ;;
508) response_message="508 Loop Detected" ;;
510) response_message="510 Not Extended" ;;
511) response_message="511 Network Authentication Required" ;;
esac
response_message="Server responded ${response_message}"
case ${response_message:17:1} in
2) notify "$response_message" ;;
3) warn "$response_message" ;;
4|5) error "$response_message" ;;
esac