mirror of
				https://github.com/PurpleI2P/i2pd.git
				synced 2025-11-04 08:30:46 +00:00 
			
		
		
		
	Started rewrite of HTTPServer.
This commit is contained in:
		
							parent
							
								
									3d30b4bbbc
								
							
						
					
					
						commit
						e7350a3af4
					
				
					 6 changed files with 269 additions and 1066 deletions
				
			
		| 
						 | 
				
			
			@ -55,8 +55,8 @@ std::string Request::getHeader(const std::string& name) const
 | 
			
		|||
    return headers.at(name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Response::Response(int status)
 | 
			
		||||
    : status(status), headers()
 | 
			
		||||
Response::Response(int status, const std::string& content)
 | 
			
		||||
    : status(status), content(content), headers()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -72,7 +72,7 @@ std::string Response::toString() const
 | 
			
		|||
    ss << "HTTP/1.1 " << status << ' ' << getStatusMessage() << "\r\n";
 | 
			
		||||
    for(auto& pair : headers)
 | 
			
		||||
        ss << pair.first << ": " << pair.second << "\r\n";
 | 
			
		||||
    ss << "\r\n"; 
 | 
			
		||||
    ss << "\r\n" << content; 
 | 
			
		||||
    return ss.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -99,6 +99,12 @@ std::string Response::getStatusMessage() const
 | 
			
		|||
            return std::string();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Response::setContentLength()
 | 
			
		||||
{
 | 
			
		||||
    setHeader("Content-Length", std::to_string(content.size()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,9 +14,9 @@ class Request {
 | 
			
		|||
 | 
			
		||||
    void parseHeaderLine(const std::string& line);
 | 
			
		||||
public:
 | 
			
		||||
    Request(const std::string& data);
 | 
			
		||||
    Request() = default;
 | 
			
		||||
 | 
			
		||||
    Request();
 | 
			
		||||
    Request(const std::string& data);
 | 
			
		||||
 | 
			
		||||
    std::string getMethod() const;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -41,8 +41,9 @@ private:
 | 
			
		|||
 | 
			
		||||
class Response {
 | 
			
		||||
public:
 | 
			
		||||
    Response() = default;
 | 
			
		||||
 | 
			
		||||
    Response(int status);
 | 
			
		||||
    Response(int status, const std::string& content = "");
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @note overrides existing header values with the same name
 | 
			
		||||
| 
						 | 
				
			
			@ -57,8 +58,11 @@ public:
 | 
			
		|||
     */
 | 
			
		||||
    std::string getStatusMessage() const;
 | 
			
		||||
 | 
			
		||||
    void setContentLength();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    int status;
 | 
			
		||||
    std::string content;
 | 
			
		||||
    std::map<std::string, std::string> headers;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue