aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils/http_util
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-10-03 00:38:15 -0400
committerJack Lloyd <[email protected]>2017-10-03 00:38:15 -0400
commit04d64c3e0fe60a25b1f1a5c2eaf7e2986d2130dd (patch)
tree3dc2cc7e970fc5f1cdc94887b03704d82c37e07e /src/lib/utils/http_util
parent180540de74c58a72492692f58b63f32647e80bd8 (diff)
Add wrappers for reinterpret_cast between char* and uint8_t*
Generally speaking reinterpret_cast is sketchy stuff. But the special case of char*/uint8_t* is both common and safe. By isolating those, the remaining (likely sketchy) cases are easier to grep for.
Diffstat (limited to 'src/lib/utils/http_util')
-rw-r--r--src/lib/utils/http_util/http_util.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/lib/utils/http_util/http_util.cpp b/src/lib/utils/http_util/http_util.cpp
index 73efb7adc..035176c17 100644
--- a/src/lib/utils/http_util/http_util.cpp
+++ b/src/lib/utils/http_util/http_util.cpp
@@ -40,7 +40,7 @@ std::string http_transact(const std::string& hostname,
}
// Blocks until entire message has been written
- socket->write(reinterpret_cast<const uint8_t*>(message.data()),
+ socket->write(cast_char_ptr_to_uint8(message.data()),
message.size());
std::ostringstream oss;
@@ -51,7 +51,7 @@ std::string http_transact(const std::string& hostname,
if(got == 0) // EOF
break;
- oss.write(reinterpret_cast<const char*>(buf.data()),
+ oss.write(cast_uint8_ptr_to_char(buf.data()),
static_cast<std::streamsize>(got));
}
@@ -75,7 +75,7 @@ std::string url_encode(const std::string& in)
else if(c == '-' || c == '_' || c == '.' || c == '~')
out << c;
else
- out << '%' << hex_encode(reinterpret_cast<uint8_t*>(&c), 1);
+ out << '%' << hex_encode(cast_char_ptr_to_uint8(&c), 1);
}
return out.str();
@@ -87,7 +87,7 @@ std::ostream& operator<<(std::ostream& o, const Response& resp)
for(auto h : resp.headers())
o << "Header '" << h.first << "' = '" << h.second << "'\n";
o << "Body " << std::to_string(resp.body().size()) << " bytes:\n";
- o.write(reinterpret_cast<const char*>(&resp.body()[0]), resp.body().size());
+ o.write(cast_uint8_ptr_to_char(resp.body().data()), resp.body().size());
return o;
}
@@ -136,7 +136,7 @@ Response http_sync(http_exch_fn http_transact,
if(!content_type.empty())
outbuf << "Content-Type: " << content_type << "\r\n";
outbuf << "Connection: close\r\n\r\n";
- outbuf.write(reinterpret_cast<const char*>(body.data()), body.size());
+ outbuf.write(cast_uint8_ptr_to_char(body.data()), body.size());
std::istringstream io(http_transact(hostname, outbuf.str()));
@@ -184,7 +184,7 @@ Response http_sync(http_exch_fn http_transact,
std::vector<uint8_t> buf(4096);
while(io.good())
{
- io.read(reinterpret_cast<char*>(buf.data()), buf.size());
+ io.read(cast_uint8_ptr_to_char(buf.data()), buf.size());
resp_body.insert(resp_body.end(), buf.data(), &buf[io.gcount()]);
}