ws_add_header - add HTTP header

void ws_add_header(struct websockets *ws, const char field[], const char value[])

Add a header field/value pair.

Parameters
  • ws – the WebSockets handle created with ws_init()

  • field – the header field

  • value – the header value

Example

CURLM *mhandle = curl_multi_init();
struct websockets *ws = ws_init(&cbs, mhandle, NULL);
ws_set_url(ws, "wss://example.com", NULL);

ws_add_header(ws, "Authorization", "Bearer xyz");
ws_add_header(ws, "Sec-Websocket-Protocol", "protocol");

/* run the event-loop */
ws_start(ws);

uint64_t tstamp;
bool is_running;
do {
  is_running = ws_easy_run(ws, 5, &tstamp);
} while (is_running);

ws_end(ws);

ws_cleanup(ws);
curl_multi_cleanup(mhandle);