ext/revdispatch/libdispatch-0.1/src/ev_http.cc in evdispatch-0.1.4 vs ext/revdispatch/libdispatch-0.1/src/ev_http.cc in evdispatch-0.1.5

- old
+ new

@@ -168,12 +168,17 @@ size_t HttpRequest::write_cb(void *ptr, size_t size, size_t nmemb, void *data) { size_t realsize = size * nmemb; HttpRequest *req = (HttpRequest *)data; - req->response->body.append((const char*)ptr,realsize); - //fprintf(stderr, "Write: %s (%lu) => (%d)%s\n", req->url.c_str(), realsize, (int)req->response, req->response->body.c_str() ); + if( req->response ) { + req->response->body.append((const char*)ptr,realsize); + //fprintf(stderr, "Write: %s (%lu) => (%d)%s\n", req->url.c_str(), realsize, (int)req->response, req->response->body.c_str() ); + } + else if( req->m_fd ) { + write( req->m_fd, ptr, realsize ); + } return realsize; } // CURLOPT_PROGRESSFUNCTION @@ -200,10 +205,16 @@ // setup the response object this->response->name = url; } +void HttpRequest::set_response_fd( int fd ) +{ + if( this->response ){ delete this->response; this->response = NULL; } + m_fd = fd; +} + HttpRequest::~HttpRequest() { curl_easy_cleanup( m_handle ); #ifdef DEBUG response = NULL; @@ -226,13 +237,18 @@ void HttpRequest::finish(CURLcode rc) { curl_multi_remove_handle( m_client->m_handle, m_handle ); - // add the response object here to the responses queue in the dispatcher? - // signaling to any waiting clients that their response is available - this->response->response_time = difftime( time(NULL), this->start_time ); - m_client->m_disp->send_response( this->response ); + if( this->response ) { + // add the response object here to the responses queue in the dispatcher? + // signaling to any waiting clients that their response is available + this->response->response_time = difftime( time(NULL), this->start_time ); + m_client->m_disp->send_response( this->response ); + } + else { + close( this->m_fd ); + } //fprintf( stderr, "DONE: (%s/%s) => (%d), body(%d): '%s'\n", url.c_str(), url.c_str(), rc, (int)this->response, this->response->body.c_str() ); } }