From 1500e805ddcf57950443c0b798161b4eb98957b5 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 5 Feb 2017 10:09:43 -0500 Subject: [PATCH] add is_i2p --- libi2pd/HTTP.cpp | 7 ++++++- libi2pd/HTTP.h | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libi2pd/HTTP.cpp b/libi2pd/HTTP.cpp index cc6e724b..c81b1a07 100644 --- a/libi2pd/HTTP.cpp +++ b/libi2pd/HTTP.cpp @@ -29,7 +29,7 @@ namespace http { inline bool is_http_method(const std::string & str) { return std::find(HTTP_METHODS.begin(), HTTP_METHODS.end(), str) != std::end(HTTP_METHODS); } - + void strsplit(const std::string & line, std::vector &tokens, char delim, std::size_t limit = 0) { std::size_t count = 0; std::stringstream ss(line); @@ -195,6 +195,11 @@ namespace http { return out; } + bool URL::is_i2p() const + { + return host.rfind(".i2p") == ( host.size() - 4 ); + } + void HTTPMsg::add_header(const char *name, std::string & value, bool replace) { add_header(name, value.c_str(), replace); } diff --git a/libi2pd/HTTP.h b/libi2pd/HTTP.h index 198362f5..272f2f44 100644 --- a/libi2pd/HTTP.h +++ b/libi2pd/HTTP.h @@ -56,6 +56,11 @@ namespace http * @note Returns relative url if schema if empty, absolute url otherwise */ std::string to_string (); + + /** + * @brief return true if the host is inside i2p + */ + bool is_i2p() const; }; struct HTTPMsg @@ -89,7 +94,7 @@ namespace http /** @brief Serialize HTTP request to string */ std::string to_string(); - void write(std::ostream & o); + void write(std::ostream & o); void AddHeader (const std::string& name, const std::string& value); void UpdateHeader (const std::string& name, const std::string& value); @@ -131,7 +136,7 @@ namespace http std::string to_string(); void write(std::ostream & o); - + /** @brief Checks that response declared as chunked data */ bool is_chunked() const ;