diff --git a/lib/http_parser.cpp b/lib/http_parser.cpp index f353c0dd..165d5761 100644 --- a/lib/http_parser.cpp +++ b/lib/http_parser.cpp @@ -305,12 +305,28 @@ std::string HTTP::Parser::getUrl() { } /// Returns header i, if set. -std::string HTTP::Parser::GetHeader(std::string i) { - return headers[i]; +const std::string & HTTP::Parser::GetHeader(const std::string & i) const { + if (headers.count(i)){ + return headers.at(i); + }else{ + static const std::string empty; + return empty; + } } + +/// Returns header i, if set. +bool HTTP::Parser::hasHeader(const std::string & i) const { + return headers.count(i); +} + /// Returns POST variable i, if set. -std::string HTTP::Parser::GetVar(std::string i) { - return vars[i]; +const std::string & HTTP::Parser::GetVar(const std::string & i) const { + if (vars.count(i)){ + return vars.at(i); + }else{ + static const std::string empty; + return empty; + } } std::string HTTP::Parser::allVars(){ diff --git a/lib/http_parser.h b/lib/http_parser.h index 52084ab1..5a716af6 100644 --- a/lib/http_parser.h +++ b/lib/http_parser.h @@ -16,9 +16,10 @@ namespace HTTP { Parser(); bool Read(Socket::Connection & conn); bool Read(std::string & strbuf); - std::string GetHeader(std::string i); + const std::string & GetHeader(const std::string & i) const; + bool hasHeader(const std::string & i) const; void clearHeader(const std::string & i); - std::string GetVar(std::string i); + const std::string & GetVar(const std::string & i) const; std::string getUrl(); std::string allVars(); void SetHeader(std::string i, std::string v);