src/ngx_fetch.cc
// This function should be called only once. The only argument is sucess or
// not.
This function should be called only once. The only argument is sucess or
not.
This function should be called only once . The only argument is sucess or not .
void NgxFetch::CallbackDone(bool success) {
  ngx_log_error(NGX_LOG_DEBUG, log_, 0, "NgxFetch %p: CallbackDone: %s",
                this, success ? "OK":"FAIL");
  if (async_fetch_ == NULL) {
    LOG(FATAL)
        << "BUG: NgxFetch callback called more than once on same fetch"
        << str_url_.c_str() << "(" << this << ").Please report this at"
        << "https://groups.google.com/forum/#!forum/ngx-pagespeed-discuss";
    return;
  }
  release_resolver();
  if (timeout_event_ && timeout_event_->timer_set) {
    ngx_del_timer(timeout_event_);
    timeout_event_ = NULL;
  }
  if (connection_ != NULL) {
    bool keepalive = false;
    if (success) {
      ConstStringStarVector v;
      if (async_fetch_->response_headers()->Lookup(
              StringPiece(HttpAttributes::kConnection), &v)) {
        for (size_t i = 0; i < v.size(); i++) {
          if (*v[i] == "keep-alive") {
            keepalive = true;
            break;
          } else if (*v[i] == "close") {
            break;
          }
        }
      }
      ngx_log_error(NGX_LOG_DEBUG, log_, 0,
                    "NgxFetch %p: connection %p attempt keep-alive: %s",
                    this, connection_, keepalive ? "Yes":"No");
    }
    connection_->set_keepalive(keepalive);
    connection_->Close();
    connection_ = NULL;
  }
  if (fetcher_ != NULL) {
    if (fetcher_->track_original_content_length()
        && async_fetch_->response_headers()->Has(
            HttpAttributes::kXOriginalContentLength)) {
      async_fetch_->extra_response_headers()->SetOriginalContentLength(
          bytes_received_);
    }
    fetcher_->FetchComplete(this);
  }
  async_fetch_->Done(success);
  async_fetch_ = NULL;
}
void NgxFetch :: CallbackDone ( bool success ) { ngx_log_error ( NGX_LOG_DEBUG , log_ , 0 , " " , this , success ? " " : " " ) ; if ( async_fetch_ == NULL ) { LOG ( FATAL ) << " " << str_url_ . c_str ( ) << " " << this << " " << " " ; return ; } release_resolver ( ) ; if ( timeout_event_ && timeout_event_ -> timer_set ) { ngx_del_timer ( timeout_event_ ) ; timeout_event_ = NULL ; } if ( connection_ != NULL ) { bool keepalive = false ; if ( success ) { ConstStringStarVector v ; if ( async_fetch_ -> response_headers ( ) -> Lookup ( StringPiece ( HttpAttributes :: kConnection ) , & v ) ) { for ( size_t i = 0 ; i < v . size ( ) ; i ++ ) { if ( * v [ i ] == " " ) { keepalive = true ; break ; } else if ( * v [ i ] == " " ) { break ; } } } ngx_log_error ( NGX_LOG_DEBUG , log_ , 0 , " " , this , connection_ , keepalive ? " " : " " ) ; } connection_ -> set_keepalive ( keepalive ) ; connection_ -> Close ( ) ; connection_ = NULL ; } if ( fetcher_ != NULL ) { if ( fetcher_ -> track_original_content_length ( ) && async_fetch_ -> response_headers ( ) -> Has ( HttpAttributes :: kXOriginalContentLength ) ) { async_fetch_ -> extra_response_headers ( ) -> SetOriginalContentLength ( bytes_received_ ) ; } fetcher_ -> FetchComplete ( this ) ; } async_fetch_ -> Done ( success ) ; async_fetch_ = NULL ; }
This function should be called only once.
This function should be called only once .
// Connection will be re-used only on responses that specify // 'Connection: keep-alive' in their headers.