| 138 | } // namespace |
| 139 | |
| 140 | bool HttpHeaderProcessor::parse(const unsigned char* data, size_t length) |
| 141 | { |
| 142 | size_t i; |
| 143 | lastBytesProcessed_ = 0; |
| 144 | for (i = 0; i < length; ++i) { |
| 145 | unsigned char c = data[i]; |
| 146 | switch (state_) { |
| 147 | case PREV_METHOD: |
| 148 | if (util::isLws(c) || util::isCRLF(c)) { |
| 149 | throw DL_ABORT_EX("Bad Request-Line: missing method"); |
| 150 | } |
| 151 | |
| 152 | i = getToken(buf_, data, length, i); |
| 153 | state_ = METHOD; |
| 154 | break; |
| 155 | |
| 156 | case METHOD: |
| 157 | if (util::isLws(c)) { |
| 158 | result_->setMethod(buf_); |
| 159 | buf_.clear(); |
| 160 | state_ = PREV_PATH; |
| 161 | break; |
| 162 | } |
| 163 | |
| 164 | if (util::isCRLF(c)) { |
| 165 | throw DL_ABORT_EX("Bad Request-Line: missing request-target"); |
| 166 | } |
| 167 | |
| 168 | i = getToken(buf_, data, length, i); |
| 169 | break; |
| 170 | |
| 171 | case PREV_PATH: |
| 172 | if (util::isCRLF(c)) { |
| 173 | throw DL_ABORT_EX("Bad Request-Line: missing request-target"); |
| 174 | } |
| 175 | |
| 176 | if (util::isLws(c)) { |
| 177 | break; |
| 178 | } |
| 179 | |
| 180 | i = getToken(buf_, data, length, i); |
| 181 | state_ = PATH; |
| 182 | break; |
| 183 | |
| 184 | case PATH: |
| 185 | if (util::isLws(c)) { |
| 186 | result_->setRequestPath(buf_); |
| 187 | buf_.clear(); |
| 188 | state_ = PREV_REQ_VERSION; |
| 189 | break; |
| 190 | } |
| 191 | |
| 192 | if (util::isCRLF(c)) { |
| 193 | throw DL_ABORT_EX("Bad Request-Line: missing HTTP-version"); |
| 194 | } |
| 195 | |
| 196 | i = getToken(buf_, data, length, i); |
| 197 | break; |
nothing calls this directly
no test coverage detected