Improved HTTP library GetHeader/GetVar functions, added hasHeader function
This commit is contained in:
parent
aedc8df494
commit
e8e97adb49
2 changed files with 23 additions and 6 deletions
|
@ -305,12 +305,28 @@ std::string HTTP::Parser::getUrl() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns header i, if set.
|
/// Returns header i, if set.
|
||||||
std::string HTTP::Parser::GetHeader(std::string i) {
|
const std::string & HTTP::Parser::GetHeader(const std::string & i) const {
|
||||||
return headers[i];
|
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.
|
/// Returns POST variable i, if set.
|
||||||
std::string HTTP::Parser::GetVar(std::string i) {
|
const std::string & HTTP::Parser::GetVar(const std::string & i) const {
|
||||||
return vars[i];
|
if (vars.count(i)){
|
||||||
|
return vars.at(i);
|
||||||
|
}else{
|
||||||
|
static const std::string empty;
|
||||||
|
return empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string HTTP::Parser::allVars(){
|
std::string HTTP::Parser::allVars(){
|
||||||
|
|
|
@ -16,9 +16,10 @@ namespace HTTP {
|
||||||
Parser();
|
Parser();
|
||||||
bool Read(Socket::Connection & conn);
|
bool Read(Socket::Connection & conn);
|
||||||
bool Read(std::string & strbuf);
|
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);
|
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 getUrl();
|
||||||
std::string allVars();
|
std::string allVars();
|
||||||
void SetHeader(std::string i, std::string v);
|
void SetHeader(std::string i, std::string v);
|
||||||
|
|
Loading…
Add table
Reference in a new issue