group__HTTP-headers-create.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.11"/>
  7. <title>libwebsockets: HTTP headers: create</title>
  8. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  9. <script type="text/javascript" src="jquery.js"></script>
  10. <script type="text/javascript" src="dynsections.js"></script>
  11. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  12. <script type="text/javascript" src="resize.js"></script>
  13. <script type="text/javascript" src="navtreedata.js"></script>
  14. <script type="text/javascript" src="navtree.js"></script>
  15. <script type="text/javascript">
  16. $(document).ready(initResizable);
  17. $(window).load(resizeHeight);
  18. </script>
  19. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  20. </head>
  21. <body>
  22. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  23. <div id="titlearea">
  24. <table cellspacing="0" cellpadding="0">
  25. <tbody>
  26. <tr style="height: 56px;">
  27. <td id="projectlogo"><img alt="Logo" src="libwebsockets.org-logo.png"/></td>
  28. <td id="projectalign" style="padding-left: 0.5em;">
  29. <div id="projectname">libwebsockets
  30. </div>
  31. <div id="projectbrief">Lightweight C library for HTML5 websockets</div>
  32. </td>
  33. </tr>
  34. </tbody>
  35. </table>
  36. </div>
  37. <!-- end header part -->
  38. <!-- Generated by Doxygen 1.8.11 -->
  39. <div id="navrow1" class="tabs">
  40. <ul class="tablist">
  41. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  42. <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
  43. <li class="current"><a href="modules.html"><span>Modules</span></a></li>
  44. <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
  45. <li><a href="files.html"><span>Files</span></a></li>
  46. </ul>
  47. </div>
  48. </div><!-- top -->
  49. <div id="side-nav" class="ui-resizable side-nav-resizable">
  50. <div id="nav-tree">
  51. <div id="nav-tree-contents">
  52. <div id="nav-sync" class="sync"></div>
  53. </div>
  54. </div>
  55. <div id="splitbar" style="-moz-user-select:none;"
  56. class="ui-resizable-handle">
  57. </div>
  58. </div>
  59. <script type="text/javascript">
  60. $(document).ready(function(){initNavTree('group__HTTP-headers-create.html','');});
  61. </script>
  62. <div id="doc-content">
  63. <div class="header">
  64. <div class="summary">
  65. <a href="#func-members">Functions</a> </div>
  66. <div class="headertitle">
  67. <div class="title">HTTP headers: create<div class="ingroups"><a class="el" href="group__http.html">HTTP</a></div></div> </div>
  68. </div><!--header-->
  69. <div class="contents">
  70. <table class="memberdecls">
  71. <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
  72. Functions</h2></td></tr>
  73. <tr class="memitem:ga29b7d6d2ddfdbaff3d8b607e7e3151b6"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__HTTP-headers-create.html#ga29b7d6d2ddfdbaff3d8b607e7e3151b6">lws_add_http_header_status</a> (struct lws *wsi, unsigned int code, unsigned char **p, unsigned char *end)</td></tr>
  74. <tr class="separator:ga29b7d6d2ddfdbaff3d8b607e7e3151b6"><td class="memSeparator" colspan="2">&#160;</td></tr>
  75. <tr class="memitem:ga2b36bf44405755ff51c1939303b995a8"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__HTTP-headers-create.html#ga2b36bf44405755ff51c1939303b995a8">lws_add_http_header_by_name</a> (struct lws *wsi, const unsigned char *name, const unsigned char *value, int length, unsigned char **p, unsigned char *end)</td></tr>
  76. <tr class="separator:ga2b36bf44405755ff51c1939303b995a8"><td class="memSeparator" colspan="2">&#160;</td></tr>
  77. <tr class="memitem:gaf74adb761b22566ad70004882712dce1"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__HTTP-headers-create.html#gaf74adb761b22566ad70004882712dce1">lws_add_http_header_by_token</a> (struct lws *wsi, enum lws_token_indexes token, const unsigned char *value, int length, unsigned char **p, unsigned char *end)</td></tr>
  78. <tr class="separator:gaf74adb761b22566ad70004882712dce1"><td class="memSeparator" colspan="2">&#160;</td></tr>
  79. <tr class="memitem:gacc76a5babcb4dce1b01b1955aa7a2faf"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__HTTP-headers-create.html#gacc76a5babcb4dce1b01b1955aa7a2faf">lws_add_http_header_content_length</a> (struct lws *wsi, unsigned long content_length, unsigned char **p, unsigned char *end)</td></tr>
  80. <tr class="separator:gacc76a5babcb4dce1b01b1955aa7a2faf"><td class="memSeparator" colspan="2">&#160;</td></tr>
  81. <tr class="memitem:ga4887605ff2242a54db3a7fa01f6f864b"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__HTTP-headers-create.html#ga4887605ff2242a54db3a7fa01f6f864b">lws_finalize_http_header</a> (struct lws *wsi, unsigned char **p, unsigned char *end)</td></tr>
  82. <tr class="separator:ga4887605ff2242a54db3a7fa01f6f864b"><td class="memSeparator" colspan="2">&#160;</td></tr>
  83. </table>
  84. <a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
  85. <h2>HTTP headers: Create</h2>
  86. <p>These apis allow you to create HTTP response headers in a way compatible with both HTTP/1.x and HTTP/2.</p>
  87. <p>They each append to a buffer taking care about the buffer end, which is passed in as a pointer. When data is written to the buffer, the current position p is updated accordingly.</p>
  88. <p>All of these apis are LWS_WARN_UNUSED_RESULT as they can run out of space and fail with nonzero return. </p>
  89. <h2 class="groupheader">Function Documentation</h2>
  90. <a class="anchor" id="ga2b36bf44405755ff51c1939303b995a8"></a>
  91. <div class="memitem">
  92. <div class="memproto">
  93. <table class="memname">
  94. <tr>
  95. <td class="memname">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_add_http_header_by_name </td>
  96. <td>(</td>
  97. <td class="paramtype">struct lws *&#160;</td>
  98. <td class="paramname"><em>wsi</em>, </td>
  99. </tr>
  100. <tr>
  101. <td class="paramkey"></td>
  102. <td></td>
  103. <td class="paramtype">const unsigned char *&#160;</td>
  104. <td class="paramname"><em>name</em>, </td>
  105. </tr>
  106. <tr>
  107. <td class="paramkey"></td>
  108. <td></td>
  109. <td class="paramtype">const unsigned char *&#160;</td>
  110. <td class="paramname"><em>value</em>, </td>
  111. </tr>
  112. <tr>
  113. <td class="paramkey"></td>
  114. <td></td>
  115. <td class="paramtype">int&#160;</td>
  116. <td class="paramname"><em>length</em>, </td>
  117. </tr>
  118. <tr>
  119. <td class="paramkey"></td>
  120. <td></td>
  121. <td class="paramtype">unsigned char **&#160;</td>
  122. <td class="paramname"><em>p</em>, </td>
  123. </tr>
  124. <tr>
  125. <td class="paramkey"></td>
  126. <td></td>
  127. <td class="paramtype">unsigned char *&#160;</td>
  128. <td class="paramname"><em>end</em>&#160;</td>
  129. </tr>
  130. <tr>
  131. <td></td>
  132. <td>)</td>
  133. <td></td><td></td>
  134. </tr>
  135. </table>
  136. </div><div class="memdoc">
  137. <p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
  138. <p><a class="el" href="group__HTTP-headers-create.html#ga2b36bf44405755ff51c1939303b995a8">lws_add_http_header_by_name()</a> - append named header and value</p>
  139. <dl class="params"><dt>Parameters</dt><dd>
  140. <table class="params">
  141. <tr><td class="paramname">wsi</td><td>the connection to check </td></tr>
  142. <tr><td class="paramname">name</td><td>the hdr name, like "my-header" </td></tr>
  143. <tr><td class="paramname">value</td><td>the value after the = for this header </td></tr>
  144. <tr><td class="paramname">length</td><td>the length of the value </td></tr>
  145. <tr><td class="paramname">p</td><td>pointer to current position in buffer pointer </td></tr>
  146. <tr><td class="paramname">end</td><td>pointer to end of buffer</td></tr>
  147. </table>
  148. </dd>
  149. </dl>
  150. <p>Appends name: value to the headers </p>
  151. </div>
  152. </div>
  153. <a class="anchor" id="gaf74adb761b22566ad70004882712dce1"></a>
  154. <div class="memitem">
  155. <div class="memproto">
  156. <table class="memname">
  157. <tr>
  158. <td class="memname">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_add_http_header_by_token </td>
  159. <td>(</td>
  160. <td class="paramtype">struct lws *&#160;</td>
  161. <td class="paramname"><em>wsi</em>, </td>
  162. </tr>
  163. <tr>
  164. <td class="paramkey"></td>
  165. <td></td>
  166. <td class="paramtype">enum lws_token_indexes&#160;</td>
  167. <td class="paramname"><em>token</em>, </td>
  168. </tr>
  169. <tr>
  170. <td class="paramkey"></td>
  171. <td></td>
  172. <td class="paramtype">const unsigned char *&#160;</td>
  173. <td class="paramname"><em>value</em>, </td>
  174. </tr>
  175. <tr>
  176. <td class="paramkey"></td>
  177. <td></td>
  178. <td class="paramtype">int&#160;</td>
  179. <td class="paramname"><em>length</em>, </td>
  180. </tr>
  181. <tr>
  182. <td class="paramkey"></td>
  183. <td></td>
  184. <td class="paramtype">unsigned char **&#160;</td>
  185. <td class="paramname"><em>p</em>, </td>
  186. </tr>
  187. <tr>
  188. <td class="paramkey"></td>
  189. <td></td>
  190. <td class="paramtype">unsigned char *&#160;</td>
  191. <td class="paramname"><em>end</em>&#160;</td>
  192. </tr>
  193. <tr>
  194. <td></td>
  195. <td>)</td>
  196. <td></td><td></td>
  197. </tr>
  198. </table>
  199. </div><div class="memdoc">
  200. <p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
  201. <p><a class="el" href="group__HTTP-headers-create.html#gaf74adb761b22566ad70004882712dce1">lws_add_http_header_by_token()</a> - append given header and value</p>
  202. <dl class="params"><dt>Parameters</dt><dd>
  203. <table class="params">
  204. <tr><td class="paramname">wsi</td><td>the connection to check </td></tr>
  205. <tr><td class="paramname">token</td><td>the token index for the hdr </td></tr>
  206. <tr><td class="paramname">value</td><td>the value after the = for this header </td></tr>
  207. <tr><td class="paramname">length</td><td>the length of the value </td></tr>
  208. <tr><td class="paramname">p</td><td>pointer to current position in buffer pointer </td></tr>
  209. <tr><td class="paramname">end</td><td>pointer to end of buffer</td></tr>
  210. </table>
  211. </dd>
  212. </dl>
  213. <p>Appends name=value to the headers, but is able to take advantage of better HTTP/2 coding mechanisms where possible. </p>
  214. </div>
  215. </div>
  216. <a class="anchor" id="gacc76a5babcb4dce1b01b1955aa7a2faf"></a>
  217. <div class="memitem">
  218. <div class="memproto">
  219. <table class="memname">
  220. <tr>
  221. <td class="memname">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_add_http_header_content_length </td>
  222. <td>(</td>
  223. <td class="paramtype">struct lws *&#160;</td>
  224. <td class="paramname"><em>wsi</em>, </td>
  225. </tr>
  226. <tr>
  227. <td class="paramkey"></td>
  228. <td></td>
  229. <td class="paramtype">unsigned long&#160;</td>
  230. <td class="paramname"><em>content_length</em>, </td>
  231. </tr>
  232. <tr>
  233. <td class="paramkey"></td>
  234. <td></td>
  235. <td class="paramtype">unsigned char **&#160;</td>
  236. <td class="paramname"><em>p</em>, </td>
  237. </tr>
  238. <tr>
  239. <td class="paramkey"></td>
  240. <td></td>
  241. <td class="paramtype">unsigned char *&#160;</td>
  242. <td class="paramname"><em>end</em>&#160;</td>
  243. </tr>
  244. <tr>
  245. <td></td>
  246. <td>)</td>
  247. <td></td><td></td>
  248. </tr>
  249. </table>
  250. </div><div class="memdoc">
  251. <p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
  252. <p><a class="el" href="group__HTTP-headers-create.html#ga2b36bf44405755ff51c1939303b995a8">lws_add_http_header_by_name()</a> - append content-length helper</p>
  253. <dl class="params"><dt>Parameters</dt><dd>
  254. <table class="params">
  255. <tr><td class="paramname">wsi</td><td>the connection to check </td></tr>
  256. <tr><td class="paramname">content_length</td><td>the content length to use </td></tr>
  257. <tr><td class="paramname">p</td><td>pointer to current position in buffer pointer </td></tr>
  258. <tr><td class="paramname">end</td><td>pointer to end of buffer</td></tr>
  259. </table>
  260. </dd>
  261. </dl>
  262. <p>Appends content-length: content_length to the headers </p>
  263. </div>
  264. </div>
  265. <a class="anchor" id="ga29b7d6d2ddfdbaff3d8b607e7e3151b6"></a>
  266. <div class="memitem">
  267. <div class="memproto">
  268. <table class="memname">
  269. <tr>
  270. <td class="memname">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_add_http_header_status </td>
  271. <td>(</td>
  272. <td class="paramtype">struct lws *&#160;</td>
  273. <td class="paramname"><em>wsi</em>, </td>
  274. </tr>
  275. <tr>
  276. <td class="paramkey"></td>
  277. <td></td>
  278. <td class="paramtype">unsigned int&#160;</td>
  279. <td class="paramname"><em>code</em>, </td>
  280. </tr>
  281. <tr>
  282. <td class="paramkey"></td>
  283. <td></td>
  284. <td class="paramtype">unsigned char **&#160;</td>
  285. <td class="paramname"><em>p</em>, </td>
  286. </tr>
  287. <tr>
  288. <td class="paramkey"></td>
  289. <td></td>
  290. <td class="paramtype">unsigned char *&#160;</td>
  291. <td class="paramname"><em>end</em>&#160;</td>
  292. </tr>
  293. <tr>
  294. <td></td>
  295. <td>)</td>
  296. <td></td><td></td>
  297. </tr>
  298. </table>
  299. </div><div class="memdoc">
  300. <p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
  301. <p><a class="el" href="group__HTTP-headers-create.html#ga29b7d6d2ddfdbaff3d8b607e7e3151b6">lws_add_http_header_status()</a> - add the HTTP response status code</p>
  302. <dl class="params"><dt>Parameters</dt><dd>
  303. <table class="params">
  304. <tr><td class="paramname">wsi</td><td>the connection to check </td></tr>
  305. <tr><td class="paramname">code</td><td>an HTTP code like 200, 404 etc (see enum http_status) </td></tr>
  306. <tr><td class="paramname">p</td><td>pointer to current position in buffer pointer </td></tr>
  307. <tr><td class="paramname">end</td><td>pointer to end of buffer</td></tr>
  308. </table>
  309. </dd>
  310. </dl>
  311. <p>Adds the initial response code, so should be called first </p>
  312. </div>
  313. </div>
  314. <a class="anchor" id="ga4887605ff2242a54db3a7fa01f6f864b"></a>
  315. <div class="memitem">
  316. <div class="memproto">
  317. <table class="memname">
  318. <tr>
  319. <td class="memname">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_finalize_http_header </td>
  320. <td>(</td>
  321. <td class="paramtype">struct lws *&#160;</td>
  322. <td class="paramname"><em>wsi</em>, </td>
  323. </tr>
  324. <tr>
  325. <td class="paramkey"></td>
  326. <td></td>
  327. <td class="paramtype">unsigned char **&#160;</td>
  328. <td class="paramname"><em>p</em>, </td>
  329. </tr>
  330. <tr>
  331. <td class="paramkey"></td>
  332. <td></td>
  333. <td class="paramtype">unsigned char *&#160;</td>
  334. <td class="paramname"><em>end</em>&#160;</td>
  335. </tr>
  336. <tr>
  337. <td></td>
  338. <td>)</td>
  339. <td></td><td></td>
  340. </tr>
  341. </table>
  342. </div><div class="memdoc">
  343. <p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
  344. <p><a class="el" href="group__HTTP-headers-create.html#ga4887605ff2242a54db3a7fa01f6f864b">lws_finalize_http_header()</a> - terminate header block</p>
  345. <dl class="params"><dt>Parameters</dt><dd>
  346. <table class="params">
  347. <tr><td class="paramname">wsi</td><td>the connection to check </td></tr>
  348. <tr><td class="paramname">p</td><td>pointer to current position in buffer pointer </td></tr>
  349. <tr><td class="paramname">end</td><td>pointer to end of buffer</td></tr>
  350. </table>
  351. </dd>
  352. </dl>
  353. <p>Indicates no more headers will be added </p>
  354. </div>
  355. </div>
  356. </div><!-- contents -->
  357. </div><!-- doc-content -->
  358. <!-- start footer part -->
  359. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  360. <ul>
  361. <li class="footer">Generated by
  362. <a href="http://www.doxygen.org/index.html">
  363. <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  364. </ul>
  365. </div>
  366. </body>
  367. </html>