babelouest / ulfius

Web Framework to build REST APIs, Webservices or any HTTP endpoint in C language. Can stream large amount of data, integrate JSON data with Jansson, and create websocket services
https://babelouest.github.io/ulfius
GNU Lesser General Public License v2.1
1.07k stars 183 forks source link

Ulifus Request map_url parsing Issue: Request structure does not contain second parameter (key-value pair) onwards in request->map_url #237

Closed vediyappan-villali closed 1 year ago

vediyappan-villali commented 1 year ago

I am using the below URL and expecting all the key value pair should be in request->map_url. But I could see only 'key1' and 'value1' are present as a param (key-value pair). request->map_url->nb_values always 1 irrespective of more number of parameters and I couldn't see second param (key-value pair) onwards.

http://127.0.0.1:1234/test?key1=value1&key2=value2&key3=value3

URL used:

curl --request GET http://127.0.0.1:1234/test?key1=value1&key2=value2&key3=value3

Logs:

check_request_params: Entry check_request_params: Checking request parameters... check_request_params: map url nb_values = 1 check_request_params: map url keys = key1 check_request_params: map url values = value1 check_request_params: map url lengths = 7

babelouest commented 1 year ago

Hello @vediyappan-villali ,

Maybe something's wrong in your curl request or somewhere else.

My first guess would be your curl request, if you don't use quotes to surround the url, the shell will interpret the & character as run-in-background.

Ulfius parses all url parameters as expected if I use the following callback function using the Hello World example application base:

int callback_hello_world (const struct _u_request * request, struct _u_response * response, void * user_data) {
  ulfius_set_string_body_response(response, 200, "Hello World!");
  printf("key1: %s\n", u_map_get(request->map_url, "key1"));
  printf("key2: %s\n", u_map_get(request->map_url, "key2"));
  printf("key3: %s\n", u_map_get(request->map_url, "key3"));
  return U_CALLBACK_CONTINUE;
}

And if I run the following curl command:

curl --request GET "http://127.0.0.1:8080/helloworld?key1=value1&key2=value2&key3=value3"

I get the following output in the console running test:

$ ./test 
Start framework on port 8080
key1: value1
key2: value2
key3: value3

End framework
vediyappan-villali commented 1 year ago

@babelouest Thank you for the reply. As you said, shell interpreted the & character as run-in-background. It started working after I use quotes around the URL.