zhangmeng
2024-04-22 16935f4aebffdd1b6580b844391a0aa0f4f3012b
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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
//
// Copyright 2018 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/supplemental/http/http.h"
#include "nng/supplemental/tls/tls.h"
 
// Symbols in this file are "public" versions of the HTTP API.
// These are suitable for exposure to applications.
 
int
nng_http_req_alloc(nng_http_req **reqp, const nng_url *url)
{
#ifdef NNG_SUPP_HTTP
    nni_init();
    return (nni_http_req_alloc(reqp, url));
#else
    NNI_ARG_UNUSED(reqp);
    NNI_ARG_UNUSED(url);
    return (NNG_ENOTSUP);
#endif
}
 
void
nng_http_req_free(nng_http_req *req)
{
#ifdef NNG_SUPP_HTTP
    nni_http_req_free(req);
#else
    NNI_ARG_UNUSED(req);
#endif
}
 
void
nng_http_res_free(nng_http_res *res)
{
#ifdef NNG_SUPP_HTTP
    nni_http_res_free(res);
#else
    NNI_ARG_UNUSED(res);
#endif
}
 
int
nng_http_res_alloc(nng_http_res **resp)
{
#ifdef NNG_SUPP_HTTP
    nni_init();
    return (nni_http_res_alloc(resp));
#else
    NNI_ARG_UNUSED(resp);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_res_alloc_error(nng_http_res **resp, uint16_t code)
{
    nni_init();
#ifdef NNG_SUPP_HTTP
    return (nni_http_res_alloc_error(resp, code));
#else
    NNI_ARG_UNUSED(resp);
    NNI_ARG_UNUSED(code);
    return (NNG_ENOTSUP);
#endif
}
 
const char *
nng_http_req_get_header(nng_http_req *req, const char *key)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_req_get_header(req, key));
#else
    NNI_ARG_UNUSED(req);
    NNI_ARG_UNUSED(key);
    return (NULL);
#endif
}
 
const char *
nng_http_res_get_header(nng_http_res *res, const char *key)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_res_get_header(res, key));
#else
    NNI_ARG_UNUSED(res);
    NNI_ARG_UNUSED(key);
    return (NULL);
#endif
}
 
int
nng_http_req_add_header(nng_http_req *req, const char *key, const char *val)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_req_add_header(req, key, val));
#else
    NNI_ARG_UNUSED(req);
    NNI_ARG_UNUSED(key);
    NNI_ARG_UNUSED(val);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_res_add_header(nng_http_res *res, const char *key, const char *val)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_res_add_header(res, key, val));
#else
    NNI_ARG_UNUSED(res);
    NNI_ARG_UNUSED(key);
    NNI_ARG_UNUSED(val);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_req_set_header(nng_http_req *req, const char *key, const char *val)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_req_set_header(req, key, val));
#else
    NNI_ARG_UNUSED(req);
    NNI_ARG_UNUSED(key);
    NNI_ARG_UNUSED(val);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_res_set_header(nng_http_res *res, const char *key, const char *val)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_res_set_header(res, key, val));
#else
    NNI_ARG_UNUSED(res);
    NNI_ARG_UNUSED(key);
    NNI_ARG_UNUSED(val);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_req_del_header(nng_http_req *req, const char *key)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_req_del_header(req, key));
#else
    NNI_ARG_UNUSED(req);
    NNI_ARG_UNUSED(key);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_res_del_header(nng_http_res *res, const char *key)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_res_del_header(res, key));
#else
    NNI_ARG_UNUSED(res);
    NNI_ARG_UNUSED(key);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_req_copy_data(nng_http_req *req, const void *data, size_t sz)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_req_copy_data(req, data, sz));
#else
    NNI_ARG_UNUSED(req);
    NNI_ARG_UNUSED(data);
    NNI_ARG_UNUSED(sz);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_res_copy_data(nng_http_res *res, const void *data, size_t sz)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_res_copy_data(res, data, sz));
#else
    NNI_ARG_UNUSED(res);
    NNI_ARG_UNUSED(data);
    NNI_ARG_UNUSED(sz);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_req_set_data(nng_http_req *req, const void *data, size_t sz)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_req_set_data(req, data, sz));
#else
    NNI_ARG_UNUSED(req);
    NNI_ARG_UNUSED(data);
    NNI_ARG_UNUSED(sz);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_res_set_data(nng_http_res *res, const void *data, size_t sz)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_res_set_data(res, data, sz));
#else
    NNI_ARG_UNUSED(res);
    NNI_ARG_UNUSED(data);
    NNI_ARG_UNUSED(sz);
    return (NNG_ENOTSUP);
#endif
}
 
void
nng_http_req_get_data(nng_http_req *req, void **datap, size_t *lenp)
{
#ifdef NNG_SUPP_HTTP
    nni_http_req_get_data(req, datap, lenp);
#else
    NNI_ARG_UNUSED(req);
    *datap = NULL;
    *lenp  = 0;
#endif
}
 
void
nng_http_res_get_data(nng_http_res *res, void **datap, size_t *lenp)
{
#ifdef NNG_SUPP_HTTP
    nni_http_res_get_data(res, datap, lenp);
#else
    NNI_ARG_UNUSED(res);
    *datap = NULL;
    *lenp  = 0;
#endif
}
 
const char *
nng_http_req_get_method(nng_http_req *req)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_req_get_method(req));
#else
    NNI_ARG_UNUSED(req);
    return (NULL);
#endif
}
 
const char *
nng_http_req_get_version(nng_http_req *req)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_req_get_version(req));
#else
    NNI_ARG_UNUSED(req);
    return (NULL);
#endif
}
 
const char *
nng_http_req_get_uri(nng_http_req *req)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_req_get_uri(req));
#else
    NNI_ARG_UNUSED(req);
    return (NULL);
#endif
}
 
int
nng_http_req_set_method(nng_http_req *req, const char *meth)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_req_set_method(req, meth));
#else
    NNI_ARG_UNUSED(req);
    NNI_ARG_UNUSED(meth);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_req_set_version(nng_http_req *req, const char *vers)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_req_set_version(req, vers));
#else
    NNI_ARG_UNUSED(req);
    NNI_ARG_UNUSED(vers);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_req_set_uri(nng_http_req *req, const char *uri)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_req_set_uri(req, uri));
#else
    NNI_ARG_UNUSED(req);
    NNI_ARG_UNUSED(uri);
    return (NNG_ENOTSUP);
#endif
}
 
uint16_t
nng_http_res_get_status(nng_http_res *res)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_res_get_status(res));
#else
    NNI_ARG_UNUSED(res);
    return (0);
#endif
}
 
const char *
nng_http_res_get_version(nng_http_res *res)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_res_get_version(res));
#else
    NNI_ARG_UNUSED(res);
    return (NULL);
#endif
}
 
const char *
nng_http_res_get_reason(nng_http_res *res)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_res_get_reason(res));
#else
    NNI_ARG_UNUSED(res);
    return (NULL);
#endif
}
 
int
nng_http_res_set_status(nng_http_res *res, uint16_t status)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_res_set_status(res, status));
#else
    NNI_ARG_UNUSED(res);
    NNI_ARG_UNUSED(status);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_res_set_version(nng_http_res *res, const char *vers)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_res_set_version(res, vers));
#else
    NNI_ARG_UNUSED(res);
    NNI_ARG_UNUSED(vers);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_res_set_reason(nng_http_res *res, const char *rsn)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_res_set_reason(res, rsn));
#else
    NNI_ARG_UNUSED(res);
    NNI_ARG_UNUSED(rsn);
    return (NNG_ENOTSUP);
#endif
}
 
void
nng_http_conn_close(nng_http_conn *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_conn_read(nng_http_conn *conn, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
    nni_http_read(conn, aio);
#else
    NNI_ARG_UNUSED(conn);
    if (nni_aio_begin(aio) == 0) {
        nni_aio_finish_error(aio, NNG_ENOTSUP);
    }
#endif
}
 
void
nng_http_conn_read_all(nng_http_conn *conn, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
    nni_http_read_full(conn, aio);
#else
    NNI_ARG_UNUSED(conn);
    if (nni_aio_begin(aio) == 0) {
        nni_aio_finish_error(aio, NNG_ENOTSUP);
    }
#endif
}
 
void
nng_http_conn_write(nng_http_conn *conn, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
    nni_http_write(conn, aio);
#else
    NNI_ARG_UNUSED(conn);
    if (nni_aio_begin(aio) == 0) {
        nni_aio_finish_error(aio, NNG_ENOTSUP);
    }
#endif
}
 
void
nng_http_conn_write_all(nng_http_conn *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_conn_write_req(nng_http_conn *conn, nng_http_req *req, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
    nni_http_write_req(conn, req, aio);
#else
    NNI_ARG_UNUSED(conn);
    NNI_ARG_UNUSED(req);
    if (nni_aio_begin(aio) == 0) {
        nni_aio_finish_error(aio, NNG_ENOTSUP);
    }
#endif
}
 
void
nng_http_conn_write_res(nng_http_conn *conn, nng_http_res *res, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
    nni_http_write_res(conn, res, aio);
#else
    NNI_ARG_UNUSED(conn);
    NNI_ARG_UNUSED(res);
    if (nni_aio_begin(aio) == 0) {
        nni_aio_finish_error(aio, NNG_ENOTSUP);
    }
#endif
}
 
void
nng_http_conn_read_req(nng_http_conn *conn, nng_http_req *req, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
    nni_http_read_req(conn, req, aio);
#else
    NNI_ARG_UNUSED(conn);
    NNI_ARG_UNUSED(req);
    if (nni_aio_begin(aio) == 0) {
        nni_aio_finish_error(aio, NNG_ENOTSUP);
    }
#endif
}
 
void
nng_http_conn_read_res(nng_http_conn *conn, nng_http_res *res, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
    nni_http_read_res(conn, res, aio);
#else
    NNI_ARG_UNUSED(conn);
    NNI_ARG_UNUSED(res);
    if (nni_aio_begin(aio) == 0) {
        nni_aio_finish_error(aio, NNG_ENOTSUP);
    }
#endif
}
 
int
nng_http_handler_alloc(
    nng_http_handler **hp, const char *uri, void (*cb)(nng_aio *))
{
#ifdef NNG_SUPP_HTTP
    nni_init();
    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
}
 
int
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
}
 
int
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
}
 
int
nng_http_handler_alloc_redirect(
    nng_http_handler **hp, const char *uri, uint16_t 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
}
 
int
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
}
 
int
nng_http_handler_set_method(nng_http_handler *h, const char *meth)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_handler_set_method(h, meth));
#else
    NNI_ARG_UNUSED(h);
    NNI_ARG_UNUSED(meth);
    return (NNG_ENOTSUP);
#endif
}
 
int
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);
    return (0);
#else
    NNI_ARG_UNUSED(h);
    NNI_ARG_UNUSED(want);
    NNI_ARG_UNUSED(len);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_handler_set_host(nng_http_handler *h, const char *host)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_handler_set_host(h, host));
#else
    NNI_ARG_UNUSED(h);
    NNI_ARG_UNUSED(host);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_handler_set_tree(nng_http_handler *h)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_handler_set_tree(h));
#else
    NNI_ARG_UNUSED(h);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_handler_set_tree_exclusive(nng_http_handler *h)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_handler_set_tree_exclusive(h));
#else
    NNI_ARG_UNUSED(h);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_handler_set_data(nng_http_handler *h, void *dat, void (*dtor)(void *))
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_handler_set_data(h, dat, dtor));
#else
    NNI_ARG_UNUSED(h);
    NNI_ARG_UNUSED(dat);
    NNI_ARG_UNUSED(dtor);
    return (NNG_ENOTSUP);
#endif
}
 
void *
nng_http_handler_get_data(nng_http_handler *h)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_handler_get_data(h));
#else
    NNI_ARG_UNUSED(h);
    return (NULL);
#endif
}
 
int
nng_http_server_hold(nng_http_server **srvp, const nng_url *url)
{
#ifdef NNG_SUPP_HTTP
    nni_init();
    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
}
 
int
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
}
 
int
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
}
 
int
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
}
 
int
nng_http_server_set_error_page(
    nng_http_server *srv, uint16_t 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
}
 
int
nng_http_server_set_error_file(
    nng_http_server *srv, uint16_t code, const char *path)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_server_set_error_file(srv, code, path));
#else
    NNI_ARG_UNUSED(srv);
    NNI_ARG_UNUSED(code);
    NNI_ARG_UNUSED(path);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_server_set_tls(nng_http_server *srv, struct 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
}
 
int
nng_http_server_get_tls(nng_http_server *srv, struct 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
}
 
int
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
}
 
int
nng_http_server_res_error(nng_http_server *srv, nng_http_res *res)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_server_res_error(srv, res));
#else
    NNI_ARG_UNUSED(srv);
    NNI_ARG_UNUSED(res);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_hijack(nng_http_conn *conn)
{
#ifdef NNG_SUPP_HTTP
    return (nni_http_hijack(conn));
#else
    NNI_ARG_UNUSED(conn);
    return (NNG_ENOTSUP);
#endif
}
 
int
nng_http_client_alloc(nng_http_client **clip, const nng_url *url)
{
#ifdef NNG_SUPP_HTTP
    nni_init();
    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
}
 
int
nng_http_client_set_tls(nng_http_client *cli, struct 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
}
 
int
nng_http_client_get_tls(nng_http_client *cli, struct 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);
    if (nni_aio_begin(aio) == 0) {
        nni_aio_finish_error(aio, NNG_ENOTSUP);
    }
#endif
}
 
void
nng_http_client_transact(
    nng_http_client *cli, nng_http_req *req, nng_http_res *res, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
    nni_http_transact(cli, req, res, aio);
#else
    NNI_ARG_UNUSED(cli);
    NNI_ARG_UNUSED(req);
    NNI_ARG_UNUSED(res);
    if (nni_aio_begin(aio) == 0) {
        nni_aio_finish_error(aio, NNG_ENOTSUP);
    }
#endif
}
 
void
nng_http_conn_transact(
    nng_http_conn *conn, nng_http_req *req, nng_http_res *res, nng_aio *aio)
{
#ifdef NNG_SUPP_HTTP
    nni_http_transact_conn(conn, req, res, aio);
#else
    NNI_ARG_UNUSED(conn);
    NNI_ARG_UNUSED(req);
    NNI_ARG_UNUSED(res);
    if (nni_aio_begin(aio) == 0) {
        nni_aio_finish_error(aio, NNG_ENOTSUP);
    }
#endif
}
 
void
nng_http_req_reset(nng_http_req *req)
{
#ifdef NNG_SUPP_HTTP
    nni_http_req_reset(req);
#else
    NNI_ARG_UNUSED(req);
#endif
}
 
void
nng_http_res_reset(nng_http_res *res)
{
#ifdef NNG_SUPP_HTTP
    nni_http_res_reset(res);
#else
    NNI_ARG_UNUSED(res);
#endif
}