コード例 #1
0
void RequestMultipartParser::parse_multipart(const HttpServer::request&, ServerTraits::Response response, Params& params)
{
  logger << Logger::Debug << "Going for multipart/form-data parsing" << Logger::endl;
  MultipartParser multipart_parser;

  multipart_parser.initialize(params);
  callback = [this, &multipart_parser, &params](boost::iterator_range<char const*> range,
                      boost::system::error_code error_code,
                      size_t size_read,
                      HttpServer::connection_ptr connection_ptr)
  {
    multipart_parser.sem.Wait();
    multipart_parser.total_read += size_read;
    for (unsigned int i = 0 ; i < size_read ; ++i)
      multipart_parser.read_buffer += range[i];
    multipart_parser.parse(params);
    if (multipart_parser.total_read < multipart_parser.to_read)
      connection_ptr->read(callback);
    else
      params.response_parsed.Post();
    multipart_parser.sem.Post();
  };
  response->read(callback);
  params.response_parsed.Wait();
}
コード例 #2
0
void RequestMultipartParser::parse_multipart(const HttpServer::request&, ServerTraits::Response response, Params& params, function<void()> finished_callback)
{
  std::shared_ptr<PendingBody> pending_body = std::make_shared<PendingBody>(response, params);

  pending_body->finished_callback = finished_callback;
  response->read([this, pending_body](boost::iterator_range<char const*> range, boost::system::error_code, size_t size_read, HttpServer::connection_ptr connection_ptr)
  {
    on_receive(pending_body, range, size_read, connection_ptr);
  });
}