简体   繁体   中英

nghttp2-asio : Proper way to set content-type in header

I came up with this code, but not sure if it is right usage:

    boost::system::error_code ec;

    nghttp2::asio_http2::header_map headers;
    headers.insert(std::pair<std::string, nghttp2::asio_http2::header_value>("content-type", {"application/json; charset=utf-8", false}));
    headers.insert(std::pair<std::string, nghttp2::asio_http2::header_value>("content-length",{std::to_string(r.length()), false}));

    auto req = session->submit(ec, "POST", uri, r.data(), headers);

Could anybody tell me if this is correct usage.

Thanks

Yes, what you have done is correct way of setting a header in nghttp2 asio . Please read the documentation to know the usage of the sensitive field here .

For brevity, you can use std::make_pair . For example:

headers.insert(std::make_pair("content-type", {"application/json; charset=utf-8", false}));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM