| 116 | } |
| 117 | |
| 118 | bool http_service::doService(int type, HttpRequest& req, HttpResponse& res) |
| 119 | { |
| 120 | if (type < http_handler_get || type >= http_handler_max) { |
| 121 | logger_error("invalid type=%d", type); |
| 122 | return false; |
| 123 | } |
| 124 | |
| 125 | res.setKeepAlive(req.isKeepAlive()); |
| 126 | bool keep = req.isKeepAlive(); |
| 127 | |
| 128 | const char* path = req.getPathInfo(); |
| 129 | if (path == NULL || *path == 0) { |
| 130 | res.setStatus(400); |
| 131 | acl::string buf("400 bad request\r\n"); |
| 132 | res.setContentLength(buf.size()); |
| 133 | return res.write(buf.c_str(), buf.size()) && keep; |
| 134 | } |
| 135 | |
| 136 | size_t len = strlen(path); |
| 137 | acl::string buf(path); |
| 138 | if (path[len - 1] != '/') { |
| 139 | buf += '/'; |
| 140 | } |
| 141 | buf.lower(); |
| 142 | |
| 143 | std::map<acl::string, http_handler_t>::iterator it |
| 144 | = handlers_[type].find(buf); |
| 145 | |
| 146 | if (it != handlers_[type].end()) { |
| 147 | return it->second(req, res) && keep; |
| 148 | } |
| 149 | |
| 150 | return handler_default_(buf, req, res) && keep; |
| 151 | } |
nothing calls this directly
no test coverage detected