void HTTPResponseTest::testRead1() { std::string s("HTTP/1.1 500 Internal Server Error\r\n\r\n"); std::istringstream istr(s); HTTPResponse response; response.read(istr); assert (response.getStatus() == HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); assert (response.getReason() == "Internal Server Error"); assert (response.getVersion() == HTTPMessage::HTTP_1_1); assert (response.empty()); assert (istr.get() == -1); }
void HTTPResponseTest::testRead3() { std::string s("HTTP/1.1 200 \r\nContent-Length: 0\r\n\r\n"); std::istringstream istr(s); HTTPResponse response; response.read(istr); assert (response.getVersion() == HTTPMessage::HTTP_1_1); assert (response.getStatus() == HTTPResponse::HTTP_OK); assert (response.getReason() == ""); assert (response.size() == 1); assert (response.getContentLength() == 0); assert (istr.get() == -1); }
void HTTPResponseTest::testRead2() { std::string s("HTTP/1.0 301 Moved Permanently\r\nLocation: http://www.appinf.com/index.html\r\nServer: Poco/1.0\r\n\r\n"); std::istringstream istr(s); HTTPResponse response; response.read(istr); assert (response.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY); assert (response.getReason() == "Moved Permanently"); assert (response.getVersion() == HTTPMessage::HTTP_1_0); assert (response.size() == 2); assert (response["Location"] == "http://www.appinf.com/index.html"); assert (response["Server"] == "Poco/1.0"); assert (istr.get() == -1); }
void HTTPResponseTest::testInvalid1() { std::string s(256, 'x'); std::istringstream istr(s); HTTPResponse response; try { response.read(istr); fail("inavalid response - must throw"); } catch (MessageException&) { } }
void HTTPResponseTest::testInvalid3() { std::string s("HTTP/1.0 "); s.append(8000, 'x'); s.append("\r\n\r\n"); std::istringstream istr(s); HTTPResponse response; try { response.read(istr); fail("inavalid response - must throw"); } catch (MessageException&) { } }