| 276 | } |
| 277 | |
| 278 | void |
| 279 | InterceptPlugin::handleEvent(int abstract_event, void *edata) |
| 280 | { |
| 281 | TSEvent event = static_cast<TSEvent>(abstract_event); |
| 282 | LOG_DEBUG("Received event %d", event); |
| 283 | |
| 284 | switch (event) { |
| 285 | case TS_EVENT_NET_ACCEPT: |
| 286 | LOG_DEBUG("Handling net accept"); |
| 287 | state_->net_vc_ = static_cast<TSVConn>(edata); |
| 288 | state_->input_.buffer_ = TSIOBufferCreate(); |
| 289 | state_->input_.reader_ = TSIOBufferReaderAlloc(state_->input_.buffer_); |
| 290 | state_->input_.vio_ = TSVConnRead(state_->net_vc_, state_->cont_, state_->input_.buffer_, |
| 291 | INT64_MAX /* number of bytes to read - high value initially */); |
| 292 | |
| 293 | state_->hdr_buf_ = TSMBufferCreate(); |
| 294 | state_->hdr_loc_ = TSHttpHdrCreate(state_->hdr_buf_); |
| 295 | state_->request_headers_.reset(state_->hdr_buf_, state_->hdr_loc_); |
| 296 | TSHttpHdrTypeSet(state_->hdr_buf_, state_->hdr_loc_, TS_HTTP_TYPE_REQUEST); |
| 297 | break; |
| 298 | |
| 299 | case TS_EVENT_VCONN_WRITE_READY: // nothing to do |
| 300 | LOG_DEBUG("Got write ready"); |
| 301 | break; |
| 302 | |
| 303 | case TS_EVENT_VCONN_READ_READY: |
| 304 | LOG_DEBUG("Handling read ready"); |
| 305 | if (doRead()) { |
| 306 | break; |
| 307 | } |
| 308 | // else fall through into the next shut down cases |
| 309 | LOG_ERROR("Error while reading request!"); |
| 310 | // fallthrough |
| 311 | |
| 312 | case TS_EVENT_VCONN_READ_COMPLETE: // fall throughs intentional |
| 313 | case TS_EVENT_VCONN_WRITE_COMPLETE: |
| 314 | case TS_EVENT_VCONN_EOS: |
| 315 | case TS_EVENT_ERROR: // erroring out, nothing more to do |
| 316 | case TS_EVENT_NET_ACCEPT_FAILED: // somebody canceled the transaction |
| 317 | if (event == TS_EVENT_ERROR) { |
| 318 | LOG_ERROR("Unknown Error!"); |
| 319 | } else if (event == TS_EVENT_NET_ACCEPT_FAILED) { |
| 320 | LOG_ERROR("Got net_accept_failed!"); |
| 321 | } |
| 322 | LOG_DEBUG("Shutting down intercept"); |
| 323 | destroyCont(state_); |
| 324 | break; |
| 325 | |
| 326 | default: |
| 327 | LOG_ERROR("Unknown event %d", event); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | namespace |
| 332 | { |
no test coverage detected