1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
|
//
// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt). A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//
#include "../../core/nng_impl.h"
#include "http_api.h"
#include "nng/http.h"
// Symbols in this file are "public" versions of the HTTP API.
// These are suitable for exposure to applications.
const char *
nng_http_get_header(nng_http *conn, const char *key)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_get_header(conn, key));
#else
NNI_ARG_UNUSED(conn);
NNI_ARG_UNUSED(key);
return (NULL);
#endif
}
nng_err
nng_http_set_header(nng_http *conn, const char *key, const char *val)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_set_header(conn, key, val));
#else
NNI_ARG_UNUSED(conn);
NNI_ARG_UNUSED(key);
NNI_ARG_UNUSED(val);
return (NNG_ENOTSUP);
#endif
}
nng_err
nng_http_add_header(nng_http *conn, const char *key, const char *val)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_add_header(conn, key, val));
#else
NNI_ARG_UNUSED(conn);
NNI_ARG_UNUSED(key);
NNI_ARG_UNUSED(val);
return (NNG_ENOTSUP);
#endif
}
void
nng_http_del_header(nng_http *conn, const char *key)
{
#ifdef NNG_SUPP_HTTP
nni_http_del_header(conn, key);
#else
NNI_ARG_UNUSED(conn);
NNI_ARG_UNUSED(key);
#endif
}
void
nng_http_set_body(nng_http *conn, void *data, size_t sz)
{
#ifdef NNG_SUPP_HTTP
nni_http_set_body(conn, data, sz);
#else
NNI_ARG_UNUSED(conn);
NNI_ARG_UNUSED(data);
NNI_ARG_UNUSED(sz);
return;
#endif
}
nng_err
nng_http_copy_body(nng_http *conn, const void *data, size_t len)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_copy_body(conn, data, len));
#else
NNI_ARG_UNUSED(conn);
NNI_ARG_UNUSED(data);
NNI_ARG_UNUSED(len);
return (NNG_ENOTSUP);
#endif
}
void
nng_http_get_body(nng_http *conn, void **datap, size_t *lenp)
{
#ifdef NNG_SUPP_HTTP
nni_http_get_body(conn, datap, lenp);
#else
NNI_ARG_UNUSED(conn);
NNI_ARG_UNUSED(datap);
NNI_ARG_UNUSED(lenp);
#endif
}
const char *
nng_http_get_uri(nng_http *conn)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_get_uri(conn));
#else
NNI_ARG_UNUSED(conn);
return (NULL);
#endif
}
nng_err
nng_http_set_uri(nng_http *conn, const char *uri, const char *query)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_set_uri(conn, uri, query));
#else
NNI_ARG_UNUSED(conn);
NNI_ARG_UNUSED(uri);
NNI_ARG_UNUSED(query);
return (NNG_ENOTSUP);
#endif
}
const char *
nng_http_get_version(nng_http *conn)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_get_version(conn));
#else
NNI_ARG_UNUSED(conn);
return (NULL);
#endif
}
void
nng_http_set_status(nng_http *conn, nng_http_status status, const char *reason)
{
#ifdef NNG_SUPP_HTTP
nni_http_set_status(conn, status, reason);
#else
NNI_ARG_UNUSED(conn);
NNI_ARG_UNUSED(status);
NNI_ARG_UNUSED(reason);
#endif
}
nng_http_status
nng_http_get_status(nng_http *conn)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_get_status(conn));
#else
NNI_ARG_UNUSED(conn);
return (0);
#endif
}
const char *
nng_http_get_reason(nng_http *conn)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_get_reason(conn));
#else
NNI_ARG_UNUSED(conn);
return (0);
#endif
}
nng_err
nng_http_set_version(nng_http *conn, const char *version)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_set_version(conn, version));
#else
return (NNG_ENOTSUP);
#endif
}
void
nng_http_set_method(nng_http *conn, const char *method)
{
#ifdef NNG_SUPP_HTTP
nni_http_set_method(conn, method);
#else
NNI_ARG_UNUSED(conn);
NNI_ARG_UNUSED(method);
#endif
}
const char *
nng_http_get_method(nng_http *conn)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_get_method(conn));
#else
NNI_ARG_UNUSED(conn);
return (NULL);
#endif
}
void
nng_http_close(nng_http *conn)
{
#ifdef NNG_SUPP_HTTP
// API version of this closes *and* frees the structure.
nni_http_conn_fini(conn);
#else
NNI_ARG_UNUSED(conn);
#endif
}
void
nng_http_read(nng_http *conn, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
nni_http_read(conn, aio);
#else
NNI_ARG_UNUSED(conn);
nni_aio_finish_error(aio, NNG_ENOTSUP);
#endif
}
void
nng_http_read_all(nng_http *conn, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
nni_http_read_full(conn, aio);
#else
NNI_ARG_UNUSED(conn);
nni_aio_finish_error(aio, NNG_ENOTSUP);
#endif
}
void
nng_http_write(nng_http *conn, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
nni_http_write(conn, aio);
#else
NNI_ARG_UNUSED(conn);
nni_aio_finish_error(aio, NNG_ENOTSUP);
#endif
}
void
nng_http_write_all(nng_http *conn, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
nni_http_write_full(conn, aio);
#else
NNI_ARG_UNUSED(conn);
NNI_ARG_UNUSED(aio);
#endif
}
void
nng_http_write_request(nng_http *conn, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
nni_http_write_req(conn, aio);
#else
NNI_ARG_UNUSED(conn);
nni_aio_finish_error(aio, NNG_ENOTSUP);
#endif
}
void
nng_http_write_response(nng_http *conn, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
nni_http_write_res(conn, aio);
#else
NNI_ARG_UNUSED(conn);
nni_aio_finish_error(aio, NNG_ENOTSUP);
#endif
}
void
nng_http_read_response(nng_http *conn, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
nni_http_read_res(conn, aio);
#else
NNI_ARG_UNUSED(conn);
nni_aio_finish_error(aio, NNG_ENOTSUP);
#endif
}
nng_err
nng_http_handler_alloc(
nng_http_handler **hp, const char *uri, nng_http_handler_func cb)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_handler_init(hp, uri, cb));
#else
NNI_ARG_UNUSED(hp);
NNI_ARG_UNUSED(uri);
NNI_ARG_UNUSED(cb);
return (NNG_ENOTSUP);
#endif
}
void
nng_http_handler_free(nng_http_handler *h)
{
#ifdef NNG_SUPP_HTTP
nni_http_handler_fini(h);
#else
NNI_ARG_UNUSED(h);
#endif
}
nng_err
nng_http_handler_alloc_file(
nng_http_handler **hp, const char *uri, const char *path)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_handler_init_file(hp, uri, path));
#else
NNI_ARG_UNUSED(hp);
NNI_ARG_UNUSED(uri);
NNI_ARG_UNUSED(path);
return (NNG_ENOTSUP);
#endif
}
nng_err
nng_http_handler_alloc_directory(
nng_http_handler **hp, const char *uri, const char *path)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_handler_init_directory(hp, uri, path));
#else
NNI_ARG_UNUSED(hp);
NNI_ARG_UNUSED(uri);
NNI_ARG_UNUSED(path);
return (NNG_ENOTSUP);
#endif
}
nng_err
nng_http_handler_alloc_redirect(nng_http_handler **hp, const char *uri,
nng_http_status status, const char *where)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_handler_init_redirect(hp, uri, status, where));
#else
NNI_ARG_UNUSED(hp);
NNI_ARG_UNUSED(uri);
NNI_ARG_UNUSED(status);
NNI_ARG_UNUSED(where);
return (NNG_ENOTSUP);
#endif
}
nng_err
nng_http_handler_alloc_static(nng_http_handler **hp, const char *uri,
const void *data, size_t size, const char *ctype)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_handler_init_static(hp, uri, data, size, ctype));
#else
NNI_ARG_UNUSED(hp);
NNI_ARG_UNUSED(uri);
NNI_ARG_UNUSED(data);
NNI_ARG_UNUSED(size);
NNI_ARG_UNUSED(ctype);
return (NNG_ENOTSUP);
#endif
}
void
nng_http_handler_set_method(nng_http_handler *h, const char *meth)
{
#ifdef NNG_SUPP_HTTP
nni_http_handler_set_method(h, meth);
#else
NNI_ARG_UNUSED(h);
NNI_ARG_UNUSED(meth);
#endif
}
void
nng_http_handler_collect_body(nng_http_handler *h, bool want, size_t len)
{
#ifdef NNG_SUPP_HTTP
nni_http_handler_collect_body(h, want, len);
#else
NNI_ARG_UNUSED(h);
NNI_ARG_UNUSED(want);
NNI_ARG_UNUSED(len);
#endif
}
void
nng_http_handler_set_host(nng_http_handler *h, const char *host)
{
#ifdef NNG_SUPP_HTTP
nni_http_handler_set_host(h, host);
#else
NNI_ARG_UNUSED(h);
NNI_ARG_UNUSED(host);
#endif
}
void
nng_http_handler_set_tree(nng_http_handler *h)
{
#ifdef NNG_SUPP_HTTP
nni_http_handler_set_tree(h);
#else
NNI_ARG_UNUSED(h);
#endif
}
void
nng_http_handler_set_data(nng_http_handler *h, void *dat, void (*dtor)(void *))
{
#ifdef NNG_SUPP_HTTP
nni_http_handler_set_data(h, dat, dtor);
#else
NNI_ARG_UNUSED(h);
NNI_ARG_UNUSED(dat);
NNI_ARG_UNUSED(dtor);
#endif
}
nng_err
nng_http_server_hold(nng_http_server **srvp, const nng_url *url)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_server_init(srvp, url));
#else
NNI_ARG_UNUSED(srvp);
NNI_ARG_UNUSED(url);
return (NNG_ENOTSUP);
#endif
}
void
nng_http_server_release(nng_http_server *srv)
{
#ifdef NNG_SUPP_HTTP
nni_http_server_fini(srv);
#else
NNI_ARG_UNUSED(srv);
#endif
}
nng_err
nng_http_server_start(nng_http_server *srv)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_server_start(srv));
#else
NNI_ARG_UNUSED(srv);
return (NNG_ENOTSUP);
#endif
}
void
nng_http_server_stop(nng_http_server *srv)
{
#ifdef NNG_SUPP_HTTP
nni_http_server_stop(srv);
#else
NNI_ARG_UNUSED(srv);
#endif
}
nng_err
nng_http_server_add_handler(nng_http_server *srv, nng_http_handler *h)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_server_add_handler(srv, h));
#else
NNI_ARG_UNUSED(srv);
NNI_ARG_UNUSED(h);
return (NNG_ENOTSUP);
#endif
}
nng_err
nng_http_server_del_handler(nng_http_server *srv, nng_http_handler *h)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_server_del_handler(srv, h));
#else
NNI_ARG_UNUSED(srv);
NNI_ARG_UNUSED(h);
return (NNG_ENOTSUP);
#endif
}
nng_err
nng_http_server_set_error_page(
nng_http_server *srv, nng_http_status code, const char *body)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_server_set_error_page(srv, code, body));
#else
NNI_ARG_UNUSED(srv);
NNI_ARG_UNUSED(code);
NNI_ARG_UNUSED(body);
return (NNG_ENOTSUP);
#endif
}
nng_err
nng_http_server_set_tls(nng_http_server *srv, nng_tls_config *cfg)
{
#if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS)
return (nni_http_server_set_tls(srv, cfg));
#else
NNI_ARG_UNUSED(srv);
NNI_ARG_UNUSED(cfg);
return (NNG_ENOTSUP);
#endif
}
nng_err
nng_http_server_get_tls(nng_http_server *srv, nng_tls_config **cfg)
{
#if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS)
return (nni_http_server_get_tls(srv, cfg));
#else
NNI_ARG_UNUSED(srv);
NNI_ARG_UNUSED(cfg);
return (NNG_ENOTSUP);
#endif
}
nng_err
nng_http_server_get_addr(nng_http_server *srv, nng_sockaddr *addr)
{
#ifdef NNG_SUPP_HTTP
size_t size = sizeof(nng_sockaddr);
if (srv == NULL || addr == NULL)
return NNG_EINVAL;
return (nni_http_server_get(
srv, NNG_OPT_LOCADDR, addr, &size, NNI_TYPE_SOCKADDR));
#else
NNI_ARG_UNUSED(srv);
NNI_ARG_UNUSED(addr);
return (NNG_ENOTSUP);
#endif
}
nng_err
nng_http_server_error(nng_http_server *srv, nng_http *conn)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_server_error(srv, conn));
#else
NNI_ARG_UNUSED(srv);
NNI_ARG_UNUSED(conn);
return (NNG_ENOTSUP);
#endif
}
nng_err
nng_http_hijack(nng_http *conn)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_hijack(conn));
#else
NNI_ARG_UNUSED(conn);
return (NNG_ENOTSUP);
#endif
}
nng_err
nng_http_client_alloc(nng_http_client **clip, const nng_url *url)
{
#ifdef NNG_SUPP_HTTP
return (nni_http_client_init(clip, url));
#else
NNI_ARG_UNUSED(clip);
NNI_ARG_UNUSED(url);
return (NNG_ENOTSUP);
#endif
}
void
nng_http_client_free(nng_http_client *cli)
{
#ifdef NNG_SUPP_HTTP
nni_http_client_fini(cli);
#else
NNI_ARG_UNUSED(cli);
#endif
}
nng_err
nng_http_client_set_tls(nng_http_client *cli, nng_tls_config *cfg)
{
#if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS)
return (nni_http_client_set_tls(cli, cfg));
#else
NNI_ARG_UNUSED(cli);
NNI_ARG_UNUSED(cfg);
return (NNG_ENOTSUP);
#endif
}
nng_err
nng_http_client_get_tls(nng_http_client *cli, nng_tls_config **cfgp)
{
#if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS)
return (nni_http_client_get_tls(cli, cfgp));
#else
NNI_ARG_UNUSED(cli);
NNI_ARG_UNUSED(cfgp);
return (NNG_ENOTSUP);
#endif
}
void
nng_http_client_connect(nng_http_client *cli, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
nni_http_client_connect(cli, aio);
#else
NNI_ARG_UNUSED(cli);
nni_aio_finish_error(aio, NNG_ENOTSUP);
#endif
}
void
nng_http_transact(nng_http *conn, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
nni_http_transact_conn(conn, aio);
#else
NNI_ARG_UNUSED(conn);
nni_aio_finish_error(aio, NNG_ENOTSUP);
#endif
}
void
nng_http_reset(nng_http *conn)
{
#ifdef NNG_SUPP_HTTP
nni_http_conn_reset(conn);
#else
NNI_ARG_UNUSED(conn);
#endif
}
|