zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #24726
[Merge] lp:~zorba-coders/zorba/bug1207668 into lp:zorba
Federico Cavalieri has proposed merging lp:~zorba-coders/zorba/bug1207668 into lp:zorba.
Commit message:
Fixed bug 1207668
Requested reviews:
Matthias Brantner (matthias-brantner)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug1207668/+merge/178223
Fixed bug 1207668
--
https://code.launchpad.net/~zorba-coders/zorba/bug1207668/+merge/178223
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'modules/http-client/json/http-client.xq.src/http_response_parser.cpp'
--- modules/http-client/json/http-client.xq.src/http_response_parser.cpp 2013-07-30 18:35:31 +0000
+++ modules/http-client/json/http-client.xq.src/http_response_parser.cpp 2013-08-02 09:05:38 +0000
@@ -41,10 +41,12 @@
namespace http_client {
-void parse_content_type( std::string const &s, std::string *mime_type,
- std::string *charset ) {
- std::string::size_type pos = s.find( ';' );
- *mime_type = s.substr( 0, pos );
+void parse_content_type( std::string const &media_type, std::string *mime_type,
+ std::string *charset )
+{
+ std::string::size_type start = 0;
+ std::string::size_type end = media_type.find( ';' );
+ *mime_type = media_type.substr( start, end - start );
if ( std::strncmp( mime_type->c_str(), "text/", 5 ) == 0 ) {
//
@@ -61,29 +63,44 @@
} else
charset->clear();
- if ( pos != std::string::npos ) {
- //
- // Parse: charset="?XXXXX"?[ (comment)]
- //
- if ( (pos = s.find( '=' )) != std::string::npos ) {
- std::string t = s.substr( pos + 1 );
- if ( !t.empty() ) {
- if ( t[0] == '"' ) {
+ //media-type = type "/" subtype *( ";" parameter )
+ //type = token
+ //subtype = token
+ //parameter = attribute "=" value
+ //attribute = token
+ //value = token | quoted-string
+ //quoted-string = ( <"> *(qdtext) <"> )
+ //qdtext = <any TEXT except <">>
+ std::vector<std::string> fields;
+ while ((end = media_type.find(';',start)) != std::string::npos)
+ {
+ fields.push_back(media_type.substr(start,end-start));
+ start = end+1;
+ }
+ fields.push_back(media_type.substr(start));
+
+ std::vector<std::string>::iterator it = fields.begin();
+ for (;it!=fields.end();++it)
+ {
+ std::string& field =*it;
+ std::transform(field.begin(), field.end(), field.begin(), ::tolower);
+ field.erase(remove_if(field.begin(), field.end(), ::isspace), field.end());
+ if ((start = field.find("charset=")) != std::string::npos)
+ {
+ std::string t = field.substr(start + 8);
+ if (!t.empty())
+ {
+ if (t[0] == '"' && t[t.length()-1] == '"')
+ {
t.erase( 0, 1 );
- if ( (pos = t.find( '"' )) != std::string::npos )
- t.erase( pos );
- } else {
- if ( (pos = t.find( ' ' )) != std::string::npos )
- t.erase( pos );
- }
+ t.erase(t.length() -1, 1);
+ }
*charset = t;
- }
+ }
}
}
}
-
-
HttpResponseParser::HttpResponseParser(HttpResponseHandler& aHandler, CURL* aCurl,
ErrorThrower& aErrorThrower,
std::string aOverridenContentType,
=== added file 'test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset.xml.res'
--- test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset.xml.res 2013-08-02 09:05:38 +0000
@@ -0,0 +1,1 @@
+wrongone wrongone
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset2.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset2.xml.res 2013-08-02 09:05:38 +0000
@@ -0,0 +1,2 @@
+<http:request xmlns:http="http://expath.org/ns/http-client" href="zorbatest.lambda.nu:8080/http-test-data/request.php" method="POST"><http:header name="User-Agent" value="libcurl-agent/1.0"></http:header><http:header name="Host" value="zorbatest.lambda.nu:8080"></http:header><http:header name="Accept" value="*/*"></http:header><http:header name="foo" value="bar"></http:header><http:header name="Content-Type" value="multipart/form-data; boundary=----------------------------4ebf00fbcf09"></http:header><http:header name="Content-Length" value="37"></http:header><http:multipart boundary="----------------------------4ebf00fbcf09" content-type="multipart/form-data">
+ </http:multipart></http:request>
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset.xq'
--- test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset.xq 2013-08-02 09:05:38 +0000
@@ -0,0 +1,44 @@
+jsoniq version "1.0";
+import module namespace http = "http://zorba.io/modules/http-client";
+declare namespace err= "http://www.w3.org/2005/xqt-errors";
+
+variable $res;
+try
+{{
+variable $req:= {
+ "method": "POST",
+ "href": "http://zorbatest.lambda.nu:8080/http-test-data/request.php",
+ "headers": {"foo":"bar"},
+ "body": {
+ "media-type": "text/plain; something=charset; charSET = \"wrongone\" ; somethingelse=charset",
+ "content": "
+ Dies ist ein kleiner Test
+ "
+}};
+http:send-request($req);
+}}
+catch http:CHARSET
+{{
+ $res := fn:substring-before($err:description,":");
+}}
+
+try
+{{
+variable $req:= {
+ "method": "POST",
+ "href": "http://zorbatest.lambda.nu:8080/http-test-data/request.php",
+ "headers": {"foo":"bar"},
+ "body": {
+ "media-type": "text/plain; charsetsomething=charset; charSET =wrongone; somethingelse=charset",
+ "content": "
+ Dies ist ein kleiner Test
+ "
+}};
+http:send-request($req);
+}}
+catch http:CHARSET
+{{
+ $res := ($res, fn:substring-before($err:description,":"));
+}}
+
+$res
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset2.xq'
--- test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset2.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset2.xq 2013-08-02 09:05:38 +0000
@@ -0,0 +1,17 @@
+jsoniq version "1.0";
+import module namespace http = "http://zorba.io/modules/http-client";
+declare namespace err= "http://www.w3.org/2005/xqt-errors";
+
+variable $req2:=
+{
+ "method": "POST",
+ "href": "http://zorbatest.lambda.nu:8080/http-test-data/request.php",
+ "headers": {"foo":"bar"},
+ "body": {
+ "media-type": "multipart/form-data; boundary=----------------------------4ebf00fbcf09",
+ "content": "
+ Dies ist ein kleiner Test
+ "
+}};
+
+parse-xml(http:send-request($req2)("body")("content"))
\ No newline at end of file
Follow ups