Skip to content
Browse files

Added some DEBUG0 to request_parser. Json shortcut response now the p…

…roper mime/type. Request querys now can be without value.

The request querys without value allow to have http://localhost:8080/?test instead of ?test=1, and also ?test&test2&test3. In such case the value is empty, but not NULL.
  • Loading branch information...
1 parent 5916870 commit 4f181df81d9344209a03b7cf09c47949b2fbeb7f @davidmoreno committed
Showing with 32 additions and 13 deletions.
  1. +22 −7 src/onion/request_parser.c
  2. +2 −0 src/onion/shortcuts.c
  3. +4 −2 tests/01-internal/02-request.c
  4. +4 −4 toolchain/dmoreno.txt
View
29 src/onion/request_parser.c
@@ -396,7 +396,7 @@ static onion_connection_status parse_POST_multipart_data(onion_request *req, oni
d--;
*d='\0';
- ONION_DEBUG("Adding POST data '%s'",multipart->name);
+ ONION_DEBUG0("Adding POST data '%s'",multipart->name);
onion_dict_add(req->POST, multipart->name, multipart->data, 0);
multipart->data=multipart->data+token->pos+1;
token->pos=0;
@@ -522,7 +522,7 @@ static onion_connection_status parse_POST_multipart_headers_key(onion_request *r
req->FILES=onion_dict_new();
onion_dict_add(req->POST,multipart->name,multipart->filename, 0);
onion_dict_add(req->FILES,multipart->name, filename, OD_DUP_VALUE);
- ONION_DEBUG("Created temporal file %s",filename);
+ ONION_DEBUG0("Created temporal file %s",filename);
req->parser=parse_POST_multipart_file;
return parse_POST_multipart_file(req, data);
@@ -599,7 +599,7 @@ static onion_connection_status parse_headers_VALUE(onion_request *req, onion_buf
char *p=token->str; // skips leading spaces
while (isspace(*p)) p++;
- //ONION_DEBUG0("Adding header %s : %s",token->extra,p);
+ ONION_DEBUG0("Adding header %s : %s",token->extra,p);
onion_dict_add(req->headers,token->extra,p, OD_DUP_VALUE|OD_FREE_KEY);
token->extra=NULL;
@@ -778,7 +778,7 @@ static int onion_request_parse_query(onion_request *req){
* The data is overwriten as necessary. It is NOT dupped, so if you free this char *p, please free the tree too.
*/
static void onion_request_parse_query_to_dict(onion_dict *dict, char *p){
- //ONION_DEBUG0("Query to dict %s",p);
+ ONION_DEBUG0("Query to dict %s",p);
char *key=NULL, *value=NULL;
int state=0; // 0 key, 1 value
key=p;
@@ -789,13 +789,21 @@ static void onion_request_parse_query_to_dict(onion_dict *dict, char *p){
value=p+1;
state=1;
}
+ else if (*p=='&'){
+ *p='\0';
+ onion_unquote_inplace(key);
+ ONION_DEBUG0("Adding key %s",key);
+ onion_dict_add(dict, key, "", 0);
+ key=p+1;
+ state=0;
+ }
}
else{
if (*p=='&'){
*p='\0';
onion_unquote_inplace(key);
onion_unquote_inplace(value);
- //ONION_DEBUG0("Adding key %s=%-16s",key,value);
+ ONION_DEBUG0("Adding key %s=%-16s",key,value);
onion_dict_add(dict, key, value, 0);
key=p+1;
state=0;
@@ -803,10 +811,17 @@ static void onion_request_parse_query_to_dict(onion_dict *dict, char *p){
}
p++;
}
- if (state!=0){
+ if (state==0){
+ if (key[0]!='\0'){
+ onion_unquote_inplace(key);
+ ONION_DEBUG0("Adding key %s",key);
+ onion_dict_add(dict, key, "", 0);
+ }
+ }
+ else{
onion_unquote_inplace(key);
onion_unquote_inplace(value);
- //ONION_DEBUG0("Adding key %s=%-16s",key,value);
+ ONION_DEBUG0("Adding key %s=%-16s",key,value);
onion_dict_add(dict, key, value, 0);
}
}
View
2 src/onion/shortcuts.c
@@ -188,6 +188,8 @@ int onion_shortcut_response_file(const char *filename, onion_request *request, o
* It converts to json the passed dict and returns it. The dict is freed before returning.
*/
int onion_shortcut_response_json(onion_dict *d, onion_request *req, onion_response *res){
+ onion_response_set_header(res, "Content-Type", "application/json");
+
onion_block *bl=onion_dict_to_json(d);
onion_dict_free(d);
char tmp[16];
View
6 tests/01-internal/02-request.c
@@ -111,7 +111,7 @@ void t03_create_add_free_full_flow(){
FAIL_IF_EQUAL(req,NULL);
FAIL_IF_NOT_EQUAL(req->socket, 0);
- ok=FILL(req,"GET /myurl%20/is/very/deeply/nested?test=test&query2=query%202&more_query=%20more%20query+10 HTTP/1.0\n");
+ ok=FILL(req,"GET /myurl%20/is/very/deeply/nested?test=test&query2=query%202&more_query=%20more%20query+10&empty&empty2 HTTP/1.0\n");
FAIL_IF_NOT(ok);
ok=FILL(req,"Host: 127.0.0.1\r\n");
FAIL_IF_NOT(ok);
@@ -131,7 +131,9 @@ void t03_create_add_free_full_flow(){
FAIL_IF_NOT_EQUAL_STR( onion_dict_get(req->GET,"test"), "test");
FAIL_IF_NOT_EQUAL_STR( onion_dict_get(req->GET,"query2"), "query 2");
FAIL_IF_NOT_EQUAL_STR( onion_dict_get(req->GET,"more_query"), " more query 10");
-
+ FAIL_IF_EQUAL(onion_request_get_query(req, "empty"), NULL);
+ FAIL_IF_EQUAL(onion_request_get_query(req, "empty2"), NULL);
+ FAIL_IF_NOT_EQUAL(onion_request_get_query(req, "empty3"), NULL);
onion_request_free(req);
View
8 toolchain/dmoreno.txt
@@ -7,14 +7,14 @@ SET(CMAKE_SYSTEM_VERSION 1)
SET(ARM yes)
-SET(CS /home/dmoreno/CodeSourcery/Sourcery_G++_Lite/)
+SET(CS /home/dmoreno/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/)
# specify the cross compiler
-SET(CMAKE_C_COMPILER ${CS}/bin/arm-none-linux-gnueabi-gcc)
-SET(CMAKE_CXX_COMPILER ${CS}/bin/arm-none-linux-gnueabi-g++)
+SET(CMAKE_C_COMPILER ${CS}/../bin/arm-none-linux-gnueabi-gcc)
+SET(CMAKE_CXX_COMPILER ${CS}/../bin/arm-none-linux-gnueabi-g++)
# where is the target environment
-SET(CMAKE_FIND_ROOT_PATH ${CS}/arm-none-linux-gnueabi/libc/usr/ )
+SET(CMAKE_FIND_ROOT_PATH ${CS}/libc/usr/ )
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

0 comments on commit 4f181df

Please sign in to comment.
Something went wrong with that request. Please try again.