Browse Source

may_minihttp reserve enough buf for json serialize (#4920)

Xudong Huang 6 years ago
parent
commit
5d1b300f72
1 changed files with 4 additions and 2 deletions
  1. 4 2
      frameworks/Rust/may-minihttp/src/main.rs

+ 4 - 2
frameworks/Rust/may-minihttp/src/main.rs

@@ -6,7 +6,7 @@ extern crate serde_derive;
 extern crate may_minihttp;
 extern crate serde_json;
 
-use may_minihttp::{HttpServer, HttpService, Request, Response};
+use may_minihttp::{BodyWriter, HttpServer, HttpService, Request, Response};
 use std::io;
 
 use mimalloc::MiMalloc;
@@ -33,8 +33,10 @@ impl HttpService for Techempower {
             }
             "/json" => {
                 resp.header("Content-Type", "application/json");
+                let body = resp.body_mut();
+                body.reserve(27);
                 serde_json::to_writer(
-                    resp.body_mut(),
+                    BodyWriter(body),
                     &Message {
                         message: "Hello, World!",
                     },