aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils/http_util/http_util.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-11-21 19:53:36 -0500
committerJack Lloyd <[email protected]>2016-11-23 08:31:06 -0500
commit1f3ac78ab5652a712d5dd81af792d6bd33c296e9 (patch)
tree093e07a4631d52dffaf6a8e339f4a5be87ef98bc /src/lib/utils/http_util/http_util.cpp
parent9b95849528bf9c9d36eb5e407f0d7262f5ef6a99 (diff)
Somewhat better errors in HTTP
Diffstat (limited to 'src/lib/utils/http_util/http_util.cpp')
-rw-r--r--src/lib/utils/http_util/http_util.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/lib/utils/http_util/http_util.cpp b/src/lib/utils/http_util/http_util.cpp
index 970b90238..f0412a57e 100644
--- a/src/lib/utils/http_util/http_util.cpp
+++ b/src/lib/utils/http_util/http_util.cpp
@@ -26,6 +26,8 @@
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
+#else
+ #warning "No network support enabled in http_util"
#endif
namespace Botan {
@@ -101,7 +103,7 @@ std::string http_transact(const std::string& hostname,
ssize_t sent = ::write(fd, &message[sent_so_far], left);
if(sent < 0)
- throw HTTP_Error("HTTP server hung up on us");
+ throw HTTP_Error("write to HTTP server failed, error '" + std::string(::strerror(errno)) + "'");
else
sent_so_far += static_cast<size_t>(sent);
}
@@ -113,7 +115,7 @@ std::string http_transact(const std::string& hostname,
ssize_t got = ::read(fd, buf.data(), buf.size());
if(got < 0)
- throw HTTP_Error("HTTP server hung up on us");
+ throw HTTP_Error("read from HTTP server failed, error '" + std::string(::strerror(errno)) + "'");
else if(got > 0)
oss.write(buf.data(), static_cast<std::streamsize>(got));
else
@@ -122,8 +124,7 @@ std::string http_transact(const std::string& hostname,
return oss.str();
#else
- throw HTTP_Error("Cannot connect to " + hostname +
- ": network code disabled in build");
+ throw HTTP_Error("Cannot connect to " + hostname + ": network code disabled in build");
#endif
}
@@ -167,9 +168,12 @@ Response http_sync(http_exch_fn http_transact,
const std::vector<byte>& body,
size_t allowable_redirects)
{
+ if(url.empty())
+ throw HTTP_Error("URL empty");
+
const auto protocol_host_sep = url.find("://");
if(protocol_host_sep == std::string::npos)
- throw HTTP_Error("Invalid URL " + url);
+ throw HTTP_Error("Invalid URL '" + url + "'");
const auto host_loc_sep = url.find('/', protocol_host_sep + 3);