winlin

refine the http code.

@@ -752,7 +752,7 @@ int SrsHlsMuxer::segment_close(string log_desc) @@ -752,7 +752,7 @@ int SrsHlsMuxer::segment_close(string log_desc)
752 if (should_write_file) { 752 if (should_write_file) {
753 unlink(tmp_file.c_str()); 753 unlink(tmp_file.c_str());
754 if (unlink(tmp_file.c_str()) < 0) { 754 if (unlink(tmp_file.c_str()) < 0) {
755 - srs_warn("drop unlink path failed, file=%s.", tmp_file.c_str()); 755 + srs_warn("ignore unlink path failed, file=%s.", tmp_file.c_str());
756 } 756 }
757 } 757 }
758 758
@@ -1204,25 +1204,27 @@ int SrsHttpConn::process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -1204,25 +1204,27 @@ int SrsHttpConn::process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
1204 return ret; 1204 return ret;
1205 } 1205 }
1206 1206
1207 -SrsStaticHttpConn::SrsStaticHttpConn(IConnectionManager* cm, st_netfd_t fd, ISrsHttpServeMux* m) 1207 +SrsResponseOnlyHttpConn::SrsResponseOnlyHttpConn(IConnectionManager* cm, st_netfd_t fd, ISrsHttpServeMux* m)
1208 : SrsHttpConn(cm, fd, m) 1208 : SrsHttpConn(cm, fd, m)
1209 { 1209 {
1210 } 1210 }
1211 1211
1212 -SrsStaticHttpConn::~SrsStaticHttpConn() 1212 +SrsResponseOnlyHttpConn::~SrsResponseOnlyHttpConn()
1213 { 1213 {
1214 } 1214 }
1215 1215
1216 -int SrsStaticHttpConn::on_got_http_message(ISrsHttpMessage* msg) 1216 +int SrsResponseOnlyHttpConn::on_got_http_message(ISrsHttpMessage* msg)
1217 { 1217 {
1218 int ret = ERROR_SUCCESS; 1218 int ret = ERROR_SUCCESS;
1219 1219
1220 - // TODO: FIXME: use the post body.  
1221 - std::string res; 1220 + ISrsHttpResponseReader* br = msg->body_reader();
1222 1221
1223 - // get response body.  
1224 - if ((ret = msg->body_read_all(res)) != ERROR_SUCCESS) {  
1225 - return ret; 1222 + // drop all request body.
  1223 + while (!br->eof()) {
  1224 + char body[4096];
  1225 + if ((ret = br->read(body, 4096, NULL)) != ERROR_SUCCESS) {
  1226 + return ret;
  1227 + }
1226 } 1228 }
1227 1229
1228 return ret; 1230 return ret;
@@ -394,12 +394,14 @@ private: @@ -394,12 +394,14 @@ private:
394 virtual int process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); 394 virtual int process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
395 }; 395 };
396 396
397 -// TODO: FIXME: rename to SrsResponseOnlyHttpConn.  
398 -class SrsStaticHttpConn : public SrsHttpConn 397 +/**
  398 + * drop body of request, only process the response.
  399 + */
  400 +class SrsResponseOnlyHttpConn : public SrsHttpConn
399 { 401 {
400 public: 402 public:
401 - SrsStaticHttpConn(IConnectionManager* cm, st_netfd_t fd, ISrsHttpServeMux* m);  
402 - virtual ~SrsStaticHttpConn(); 403 + SrsResponseOnlyHttpConn(IConnectionManager* cm, st_netfd_t fd, ISrsHttpServeMux* m);
  404 + virtual ~SrsResponseOnlyHttpConn();
403 public: 405 public:
404 virtual int on_got_http_message(ISrsHttpMessage* msg); 406 virtual int on_got_http_message(ISrsHttpMessage* msg);
405 }; 407 };
@@ -1219,7 +1219,7 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) @@ -1219,7 +1219,7 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
1219 #endif 1219 #endif
1220 } else if (type == SrsListenerHttpStream) { 1220 } else if (type == SrsListenerHttpStream) {
1221 #ifdef SRS_AUTO_HTTP_SERVER 1221 #ifdef SRS_AUTO_HTTP_SERVER
1222 - conn = new SrsStaticHttpConn(this, client_stfd, http_server); 1222 + conn = new SrsResponseOnlyHttpConn(this, client_stfd, http_server);
1223 #else 1223 #else
1224 srs_warn("close http client for server not support http-server"); 1224 srs_warn("close http client for server not support http-server");
1225 srs_close_stfd(client_stfd); 1225 srs_close_stfd(client_stfd);