Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The size of the body may cause problems #527

Open
gaowanlu opened this issue Sep 6, 2022 · 2 comments
Open

The size of the body may cause problems #527

gaowanlu opened this issue Sep 6, 2022 · 2 comments

Comments

@gaowanlu
Copy link

gaowanlu commented Sep 6, 2022

code block

            void POST(const std::shared_ptr<restbed::Session> session)
            {
                const auto request = session->get_request();
                long long int content_length = stoll(request->get_header("Content-Length", "0"));
                std::pair<bool, std::string> res;
                session->fetch(content_length, [](const std::shared_ptr<restbed::Session> session, const restbed::Bytes &body) -> void
                               {
                                if(body.size()>485918){//maxsize
                                    return;
                                }
                                std::cout << body.size() << std::endl;
                                // string m_body(body.begin(), body.end());
                                // std::cout << m_body.size() << std::endl;
                                // colnago::dao::Post postObj;
                                //    postObj.parse(string(body.begin(), body.end()));
                                //    colnago::server::server.postDao->INSERT(postObj);
                                   std::cout << "INSERT END" << std::endl; });
                // BaseResponse<> response(res.first, res.second);
                session->close(restbed::OK, "", {{"Content-Type", "application/json"}});
                std::cout << "POST END" << std::endl;
            }

When the size of the body is large, the lambda expression cannot be triggered, what are the possible reasons for this phenomenon?

@gaowanlu
Copy link
Author

gaowanlu commented Sep 6, 2022

POST END
779
INSERT END
POST END
947
INSERT END
POST END
1082
INSERT END
POST END
1220
INSERT END
POST END
1220
INSERT END
POST END
1334
INSERT END
POST END
1448
INSERT END
POST END
POST END

@gaowanlu
Copy link
Author

gaowanlu commented Sep 7, 2022

It's ok,now, I review HTTP_SERVICE sample.to call session->close in lambda.

            void POST(const std::shared_ptr<restbed::Session> session)
            {
                const auto request = session->get_request();
                long long int content_length = stoll(request->get_header("Content-Length", "0"));
                auto handler = [](const std::shared_ptr<restbed::Session> session, const restbed::Bytes &body) -> void
                {
                    string m_body(body.begin(), body.end());
                    colnago::dao::Post postObj;
                    postObj.parse(string(body.begin(), body.end()));
                    std::pair<bool, std::string> res = colnago::server::server.postDao->INSERT(postObj);
                    BaseResponse<> response(res.first, res.second);
                    session->close(restbed::OK, response.stringify(), {{"Content-Type", "application/json"}});
                };
                session->fetch(content_length, handler);
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant