Merge lp:~zorba-coders/zorba/bug1207668 into lp:zorba

Proposed by Federico Cavalieri
Status: Merged
Merged at revision: 11606
Proposed branch: lp:~zorba-coders/zorba/bug1207668
Merge into: lp:zorba
Diff against target: 170 lines (+102/-21)
5 files modified
modules/http-client/json/http-client.xq.src/http_response_parser.cpp (+38/-21)
test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset2.xml.res (+2/-0)
test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset.xq (+44/-0)
test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset2.xq (+17/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug1207668
Reviewer Review Type Date Requested Status
Paul J. Lucas Approve
Matthias Brantner Approve
Review via email: mp+178223@code.launchpad.net

Commit message

Description of the change

To post a comment you must log in.
Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~zorba-coders/zorba/bug1207668/+merge/178223

Progress dashboard at http://jenkins.lambda.nu/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue succeeded - proposal merged!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/http-client/json/http-client.xq.src/http_response_parser.cpp'
2--- modules/http-client/json/http-client.xq.src/http_response_parser.cpp 2013-07-30 18:35:31 +0000
3+++ modules/http-client/json/http-client.xq.src/http_response_parser.cpp 2013-08-02 09:05:38 +0000
4@@ -41,10 +41,12 @@
5
6 namespace http_client {
7
8-void parse_content_type( std::string const &s, std::string *mime_type,
9- std::string *charset ) {
10- std::string::size_type pos = s.find( ';' );
11- *mime_type = s.substr( 0, pos );
12+void parse_content_type( std::string const &media_type, std::string *mime_type,
13+ std::string *charset )
14+{
15+ std::string::size_type start = 0;
16+ std::string::size_type end = media_type.find( ';' );
17+ *mime_type = media_type.substr( start, end - start );
18
19 if ( std::strncmp( mime_type->c_str(), "text/", 5 ) == 0 ) {
20 //
21@@ -61,29 +63,44 @@
22 } else
23 charset->clear();
24
25- if ( pos != std::string::npos ) {
26- //
27- // Parse: charset="?XXXXX"?[ (comment)]
28- //
29- if ( (pos = s.find( '=' )) != std::string::npos ) {
30- std::string t = s.substr( pos + 1 );
31- if ( !t.empty() ) {
32- if ( t[0] == '"' ) {
33+ //media-type = type "/" subtype *( ";" parameter )
34+ //type = token
35+ //subtype = token
36+ //parameter = attribute "=" value
37+ //attribute = token
38+ //value = token | quoted-string
39+ //quoted-string = ( <"> *(qdtext) <"> )
40+ //qdtext = <any TEXT except <">>
41+ std::vector<std::string> fields;
42+ while ((end = media_type.find(';',start)) != std::string::npos)
43+ {
44+ fields.push_back(media_type.substr(start,end-start));
45+ start = end+1;
46+ }
47+ fields.push_back(media_type.substr(start));
48+
49+ std::vector<std::string>::iterator it = fields.begin();
50+ for (;it!=fields.end();++it)
51+ {
52+ std::string& field =*it;
53+ std::transform(field.begin(), field.end(), field.begin(), ::tolower);
54+ field.erase(remove_if(field.begin(), field.end(), ::isspace), field.end());
55+ if ((start = field.find("charset=")) != std::string::npos)
56+ {
57+ std::string t = field.substr(start + 8);
58+ if (!t.empty())
59+ {
60+ if (t[0] == '"' && t[t.length()-1] == '"')
61+ {
62 t.erase( 0, 1 );
63- if ( (pos = t.find( '"' )) != std::string::npos )
64- t.erase( pos );
65- } else {
66- if ( (pos = t.find( ' ' )) != std::string::npos )
67- t.erase( pos );
68- }
69+ t.erase(t.length() -1, 1);
70+ }
71 *charset = t;
72- }
73+ }
74 }
75 }
76 }
77
78-
79-
80 HttpResponseParser::HttpResponseParser(HttpResponseHandler& aHandler, CURL* aCurl,
81 ErrorThrower& aErrorThrower,
82 std::string aOverridenContentType,
83
84=== added file 'test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset.xml.res'
85--- test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset.xml.res 1970-01-01 00:00:00 +0000
86+++ test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset.xml.res 2013-08-02 09:05:38 +0000
87@@ -0,0 +1,1 @@
88+wrongone wrongone
89\ No newline at end of file
90
91=== added file 'test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset2.xml.res'
92--- test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset2.xml.res 1970-01-01 00:00:00 +0000
93+++ test/rbkt/ExpQueryResults/zorba/http-client/json/send-request/http3-charset2.xml.res 2013-08-02 09:05:38 +0000
94@@ -0,0 +1,2 @@
95+<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">
96+ </http:multipart></http:request>
97\ No newline at end of file
98
99=== added file 'test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset.xq'
100--- test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset.xq 1970-01-01 00:00:00 +0000
101+++ test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset.xq 2013-08-02 09:05:38 +0000
102@@ -0,0 +1,44 @@
103+jsoniq version "1.0";
104+import module namespace http = "http://zorba.io/modules/http-client";
105+declare namespace err= "http://www.w3.org/2005/xqt-errors";
106+
107+variable $res;
108+try
109+{{
110+variable $req:= {
111+ "method": "POST",
112+ "href": "http://zorbatest.lambda.nu:8080/http-test-data/request.php",
113+ "headers": {"foo":"bar"},
114+ "body": {
115+ "media-type": "text/plain; something=charset; charSET = \"wrongone\" ; somethingelse=charset",
116+ "content": "
117+ Dies ist ein kleiner Test
118+ "
119+}};
120+http:send-request($req);
121+}}
122+catch http:CHARSET
123+{{
124+ $res := fn:substring-before($err:description,":");
125+}}
126+
127+try
128+{{
129+variable $req:= {
130+ "method": "POST",
131+ "href": "http://zorbatest.lambda.nu:8080/http-test-data/request.php",
132+ "headers": {"foo":"bar"},
133+ "body": {
134+ "media-type": "text/plain; charsetsomething=charset; charSET =wrongone; somethingelse=charset",
135+ "content": "
136+ Dies ist ein kleiner Test
137+ "
138+}};
139+http:send-request($req);
140+}}
141+catch http:CHARSET
142+{{
143+ $res := ($res, fn:substring-before($err:description,":"));
144+}}
145+
146+$res
147\ No newline at end of file
148
149=== added file 'test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset2.xq'
150--- test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset2.xq 1970-01-01 00:00:00 +0000
151+++ test/rbkt/Queries/zorba/http-client/json/send-request/http3-charset2.xq 2013-08-02 09:05:38 +0000
152@@ -0,0 +1,17 @@
153+jsoniq version "1.0";
154+import module namespace http = "http://zorba.io/modules/http-client";
155+declare namespace err= "http://www.w3.org/2005/xqt-errors";
156+
157+variable $req2:=
158+{
159+ "method": "POST",
160+ "href": "http://zorbatest.lambda.nu:8080/http-test-data/request.php",
161+ "headers": {"foo":"bar"},
162+ "body": {
163+ "media-type": "multipart/form-data; boundary=----------------------------4ebf00fbcf09",
164+ "content": "
165+ Dies ist ein kleiner Test
166+ "
167+}};
168+
169+parse-xml(http:send-request($req2)("body")("content"))
170\ No newline at end of file

Subscribers

People subscribed via source and target branches