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.08k stars 182 forks source link

Emoji #236

Closed epshteinmatthew closed 2 years ago

epshteinmatthew commented 2 years ago

Is it possible to send emojis?

//for example ulfius_set_string_body_response(response, 200, "🤗");

babelouest commented 2 years ago

Hello,

It doesn't seem so, if I try with the following callback function:

int callback_get_test (const struct _u_request * request, struct _u_response * response, void * user_data) {
  ulfius_set_string_body_response(response, 200, "\U0001f602");
  return U_CALLBACK_CONTINUE;
}

the output is not an emojii, but something like 😂

I guess you would have to encode/decode the emojii to send it to the client.

babelouest commented 2 years ago

My bad, a nice person just told me I forgot to set the content-type properly, if you have a callback function like this:

int callback_get_test (const struct _u_request * request, struct _u_response * response, void * user_data) {
  u_map_put(response->map_header, "Content-Type", "text/plain; charset=utf-8");
  ulfius_set_string_body_response(response, 200, "\U0001f602");
  return U_CALLBACK_CONTINUE;
}

You have an emoji displayed in the browser, yay!

epshteinmatthew commented 2 years ago

thank you very much!