Added JSONP support. Callback query parameter is "jsoncallback".

This commit is contained in:
Tatsuhiro Tsujikawa 2011-03-14 00:57:05 +09:00
parent feb4e2e53a
commit bf01bb84b6
6 changed files with 135 additions and 24 deletions

View file

@ -5,6 +5,7 @@
#include "RecoverableException.h"
#include "util.h"
#include "array_fun.h"
#include "Base64.h"
namespace aria2 {
@ -14,6 +15,7 @@ class JsonTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testDecode);
CPPUNIT_TEST(testDecode_error);
CPPUNIT_TEST(testEncode);
CPPUNIT_TEST(testDecodeGetParams);
CPPUNIT_TEST_SUITE_END();
private:
@ -21,6 +23,7 @@ public:
void testDecode();
void testDecode_error();
void testEncode();
void testDecodeGetParams();
};
CPPUNIT_TEST_SUITE_REGISTRATION( JsonTest );
@ -443,4 +446,32 @@ void JsonTest::testEncode()
}
}
void JsonTest::testDecodeGetParams()
{
{
std::string param = util::percentEncode(Base64::encode("[1,2,3]"));
std::string query = "?params=";
query += param;
query += '&';
query += "method=sum&";
query += "id=300&";
query += "jsoncallback=cb";
json::JsonGetParam gparam = json::decodeGetParams(query);
CPPUNIT_ASSERT_EQUAL(std::string("{\"method\":\"sum\","
"\"id\":\"300\","
"\"params\":[1,2,3]}"),
gparam.request);
CPPUNIT_ASSERT_EQUAL(std::string("cb"), gparam.callback);
}
{
std::string query = "?params=";
query += util::percentEncode(Base64::encode("[{}]"));
query += '&';
query += "jsoncallback=cb";
json::JsonGetParam gparam = json::decodeGetParams(query);
CPPUNIT_ASSERT_EQUAL(std::string("[{}]"), gparam.request);
CPPUNIT_ASSERT_EQUAL(std::string("cb"), gparam.callback);
}
}
} // namespace aria2