From dc98f7590d6a6bca16481b0fe11132e7fd1fe5c9 Mon Sep 17 00:00:00 2001 From: Brandon Forehand Date: Fri, 17 Nov 2017 09:32:55 -0800 Subject: [PATCH] Add Crawl-Delay to string representation of Agent. --- src/agent.cpp | 5 +++++ test/test-agent.cpp | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/agent.cpp b/src/agent.cpp index 4ecffd7..33824c5 100644 --- a/src/agent.cpp +++ b/src/agent.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "url.h" @@ -89,6 +90,10 @@ namespace Rep std::string Agent::str() const { std::stringstream out; + if (delay_ > 0) + { + out << "Crawl-Delay: " << std::setprecision(3) << delay_ << ' '; + } out << '['; const auto& d = directives(); auto begin = d.begin(); diff --git a/test/test-agent.cpp b/test/test-agent.cpp index e5707ea..888c657 100644 --- a/test/test-agent.cpp +++ b/test/test-agent.cpp @@ -116,3 +116,12 @@ TEST(AgentTest, Str) agent.allow("/bar"); EXPECT_EQ("[Directive(Disallow: /foo), Directive(Allow: /bar)]", agent.str()); } + +TEST(AgentTest, StrWithDelay) +{ + Rep::Agent agent("a.com"); + agent.delay(1.0); + agent.disallow("/foo"); + agent.allow("/bar"); + EXPECT_EQ("Crawl-Delay: 1 [Directive(Disallow: /foo), Directive(Allow: /bar)]", agent.str()); +}