Form a 502 response, preliminary
| 49 | |
| 50 | // Form a 502 response, preliminary |
| 51 | std::string |
| 52 | string502(int const httpver) |
| 53 | { |
| 54 | static std::string msg; |
| 55 | static std::mutex mutex; |
| 56 | std::lock_guard<std::mutex> const guard(mutex); |
| 57 | |
| 58 | if (msg.empty()) { |
| 59 | std::string bodystr; |
| 60 | bodystr.append("<html>\n"); |
| 61 | bodystr.append("<head><title>502 Bad Gateway</title></head>\n"); |
| 62 | bodystr.append("<body bgcolor=\"white\">\n"); |
| 63 | bodystr.append("<center><h1>502 Bad Gateway: Missing/Malformed " |
| 64 | "Content-Range</h1></center>"); |
| 65 | bodystr.append("<hr><center>ATS/"); |
| 66 | bodystr.append(TS_VERSION_STRING); |
| 67 | bodystr.append("</center>\n"); |
| 68 | bodystr.append("</body>\n"); |
| 69 | bodystr.append("</html>\n"); |
| 70 | |
| 71 | char hverstr[64]; |
| 72 | int const hlen = |
| 73 | snprintf(hverstr, sizeof(hverstr), "HTTP/%d.%d 502 Bad Gateway\r\n", TS_HTTP_MAJOR(httpver), TS_HTTP_MINOR(httpver)); |
| 74 | msg.append(hverstr, hlen); |
| 75 | |
| 76 | char clenstr[1024]; |
| 77 | int const clen = snprintf(clenstr, sizeof(clenstr), "%lu", bodystr.size()); |
| 78 | msg.append("Content-Length: "); |
| 79 | msg.append(clenstr, clen); |
| 80 | msg.append("\r\n"); |
| 81 | |
| 82 | msg.append("\r\n"); |
| 83 | msg.append(bodystr); |
| 84 | } |
| 85 | |
| 86 | return msg; |
| 87 | } |
| 88 | |
| 89 | void |
| 90 | form416HeaderAndBody(HttpHeader &header, int64_t const contentlen, std::string const &bodystr) |
no test coverage detected