forked from haproxy/haproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmux_h1.c
3879 lines (3351 loc) · 127 KB
/
mux_h1.c
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
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* HTT/1 mux-demux for connections
*
* Copyright 2018 Christopher Faulet <cfaulet@haproxy.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
*/
#include <import/ebistree.h>
#include <haproxy/api.h>
#include <haproxy/cfgparse.h>
#include <haproxy/connection.h>
#include <haproxy/h1.h>
#include <haproxy/h1_htx.h>
#include <haproxy/h2.h>
#include <haproxy/http_htx.h>
#include <haproxy/htx.h>
#include <haproxy/istbuf.h>
#include <haproxy/log.h>
#include <haproxy/pipe-t.h>
#include <haproxy/proxy.h>
#include <haproxy/session-t.h>
#include <haproxy/stream.h>
#include <haproxy/stream_interface.h>
#include <haproxy/trace.h>
/*
* H1 Connection flags (32 bits)
*/
#define H1C_F_NONE 0x00000000
/* Flags indicating why writing output data are blocked */
#define H1C_F_OUT_ALLOC 0x00000001 /* mux is blocked on lack of output buffer */
#define H1C_F_OUT_FULL 0x00000002 /* mux is blocked on output buffer full */
/* 0x00000004 - 0x00000008 unused */
/* Flags indicating why reading input data are blocked. */
#define H1C_F_IN_ALLOC 0x00000010 /* mux is blocked on lack of input buffer */
#define H1C_F_IN_FULL 0x00000020 /* mux is blocked on input buffer full */
#define H1C_F_IN_SALLOC 0x00000040 /* mux is blocked on lack of stream's request buffer */
/* 0x00000080 unused */
/* Flags indicating the connection state */
#define H1C_F_ST_EMBRYONIC 0x00000100 /* Set when a H1 stream with no conn-stream is attached to the connection */
#define H1C_F_ST_ATTACHED 0x00000200 /* Set when a H1 stream with a conn-stream is attached to the connection (may be not READY) */
#define H1C_F_ST_IDLE 0x00000400 /* connection is idle and may be reused
* (exclusive to all H1C_F_ST flags and never set when an h1s is attached) */
#define H1C_F_ST_ERROR 0x00000800 /* connection must be closed ASAP because an error occurred (conn-stream may still be attached) */
#define H1C_F_ST_SHUTDOWN 0x00001000 /* connection must be shut down ASAP flushing output first (conn-stream may still be attached) */
#define H1C_F_ST_READY 0x00002000 /* Set in ATTACHED state with a READY conn-stream. A conn-stream is not ready when
* a TCP>H1 upgrade is in progress Thus this flag is only set if ATTACHED is also set */
#define H1C_F_ST_ALIVE (H1C_F_ST_IDLE|H1C_F_ST_EMBRYONIC|H1C_F_ST_ATTACHED)
/* 0x00004000 - 0x00008000 unused */
#define H1C_F_WANT_SPLICE 0x00010000 /* Don't read into a buffer because we want to use or we are using splicing */
#define H1C_F_ERR_PENDING 0x00020000 /* Send an error and close the connection ASAP (implies H1C_F_ST_ERROR) */
#define H1C_F_WAIT_NEXT_REQ 0x00040000 /* waiting for the next request to start, use keep-alive timeout */
#define H1C_F_UPG_H2C 0x00080000 /* set if an upgrade to h2 should be done */
#define H1C_F_CO_MSG_MORE 0x00100000 /* set if CO_SFL_MSG_MORE must be set when calling xprt->snd_buf() */
#define H1C_F_CO_STREAMER 0x00200000 /* set if CO_SFL_STREAMER must be set when calling xprt->snd_buf() */
/* 0x00400000 - 0x40000000 unusued*/
#define H1C_F_IS_BACK 0x80000000 /* Set on outgoing connection */
/*
* H1 Stream flags (32 bits)
*/
#define H1S_F_NONE 0x00000000
#define H1S_F_RX_BLK 0x00100000 /* Don't process more input data, waiting sync with output side */
#define H1S_F_TX_BLK 0x00200000 /* Don't process more output data, waiting sync with input side */
/* 0x00000004 unused */
#define H1S_F_REOS 0x00000008 /* End of input stream seen even if not delivered yet */
#define H1S_F_WANT_KAL 0x00000010
#define H1S_F_WANT_TUN 0x00000020
#define H1S_F_WANT_CLO 0x00000040
#define H1S_F_WANT_MSK 0x00000070
#define H1S_F_NOT_FIRST 0x00000080 /* The H1 stream is not the first one */
#define H1S_F_BODYLESS_RESP 0x00000100 /* Bodyless response message */
/* 0x00000200 unused */
#define H1S_F_NOT_IMPL_ERROR 0x00000400 /* Set when a feature is not implemented during the message parsing */
#define H1S_F_PARSING_ERROR 0x00000800 /* Set when an error occurred during the message parsing */
#define H1S_F_PROCESSING_ERROR 0x00001000 /* Set when an error occurred during the message xfer */
#define H1S_F_ERROR 0x00001800 /* stream error mask */
#define H1S_F_HAVE_SRV_NAME 0x00002000 /* Set during output process if the server name header was added to the request */
#define H1S_F_HAVE_O_CONN 0x00004000 /* Set during output process to know connection mode was processed */
/* H1 connection descriptor */
struct h1c {
struct connection *conn;
struct proxy *px;
uint32_t flags; /* Connection flags: H1C_F_* */
unsigned int errcode; /* Status code when an error occurred at the H1 connection level */
struct buffer ibuf; /* Input buffer to store data before parsing */
struct buffer obuf; /* Output buffer to store data after reformatting */
struct buffer_wait buf_wait; /* Wait list for buffer allocation */
struct wait_event wait_event; /* To be used if we're waiting for I/Os */
struct h1s *h1s; /* H1 stream descriptor */
struct task *task; /* timeout management task */
int idle_exp; /* idle expiration date (http-keep-alive or http-request timeout) */
int timeout; /* client/server timeout duration */
int shut_timeout; /* client-fin/server-fin timeout duration */
};
/* H1 stream descriptor */
struct h1s {
struct h1c *h1c;
struct conn_stream *cs;
uint32_t flags; /* Connection flags: H1S_F_* */
struct wait_event *subs; /* Address of the wait_event the conn_stream associated is waiting on */
struct session *sess; /* Associated session */
struct buffer rxbuf; /* receive buffer, always valid (buf_empty or real buffer) */
struct h1m req;
struct h1m res;
enum http_meth_t meth; /* HTTP request method */
uint16_t status; /* HTTP response status */
char ws_key[25]; /* websocket handshake key */
};
/* Map of headers used to convert outgoing headers */
struct h1_hdrs_map {
char *name;
struct eb_root map;
};
/* An entry in a headers map */
struct h1_hdr_entry {
struct ist name;
struct ebpt_node node;
};
/* Declare the headers map */
static struct h1_hdrs_map hdrs_map = { .name = NULL, .map = EB_ROOT };
/* trace source and events */
static void h1_trace(enum trace_level level, uint64_t mask,
const struct trace_source *src,
const struct ist where, const struct ist func,
const void *a1, const void *a2, const void *a3, const void *a4);
/* The event representation is split like this :
* h1c - internal H1 connection
* h1s - internal H1 stream
* strm - application layer
* rx - data receipt
* tx - data transmission
*
*/
static const struct trace_event h1_trace_events[] = {
#define H1_EV_H1C_NEW (1ULL << 0)
{ .mask = H1_EV_H1C_NEW, .name = "h1c_new", .desc = "new H1 connection" },
#define H1_EV_H1C_RECV (1ULL << 1)
{ .mask = H1_EV_H1C_RECV, .name = "h1c_recv", .desc = "Rx on H1 connection" },
#define H1_EV_H1C_SEND (1ULL << 2)
{ .mask = H1_EV_H1C_SEND, .name = "h1c_send", .desc = "Tx on H1 connection" },
#define H1_EV_H1C_BLK (1ULL << 3)
{ .mask = H1_EV_H1C_BLK, .name = "h1c_blk", .desc = "H1 connection blocked" },
#define H1_EV_H1C_WAKE (1ULL << 4)
{ .mask = H1_EV_H1C_WAKE, .name = "h1c_wake", .desc = "H1 connection woken up" },
#define H1_EV_H1C_END (1ULL << 5)
{ .mask = H1_EV_H1C_END, .name = "h1c_end", .desc = "H1 connection terminated" },
#define H1_EV_H1C_ERR (1ULL << 6)
{ .mask = H1_EV_H1C_ERR, .name = "h1c_err", .desc = "error on H1 connection" },
#define H1_EV_RX_DATA (1ULL << 7)
{ .mask = H1_EV_RX_DATA, .name = "rx_data", .desc = "receipt of any H1 data" },
#define H1_EV_RX_EOI (1ULL << 8)
{ .mask = H1_EV_RX_EOI, .name = "rx_eoi", .desc = "receipt of end of H1 input" },
#define H1_EV_RX_HDRS (1ULL << 9)
{ .mask = H1_EV_RX_HDRS, .name = "rx_headers", .desc = "receipt of H1 headers" },
#define H1_EV_RX_BODY (1ULL << 10)
{ .mask = H1_EV_RX_BODY, .name = "rx_body", .desc = "receipt of H1 body" },
#define H1_EV_RX_TLRS (1ULL << 11)
{ .mask = H1_EV_RX_TLRS, .name = "rx_trailerus", .desc = "receipt of H1 trailers" },
#define H1_EV_TX_DATA (1ULL << 12)
{ .mask = H1_EV_TX_DATA, .name = "tx_data", .desc = "transmission of any H1 data" },
#define H1_EV_TX_EOI (1ULL << 13)
{ .mask = H1_EV_TX_EOI, .name = "tx_eoi", .desc = "transmission of end of H1 input" },
#define H1_EV_TX_HDRS (1ULL << 14)
{ .mask = H1_EV_TX_HDRS, .name = "tx_headers", .desc = "transmission of all headers" },
#define H1_EV_TX_BODY (1ULL << 15)
{ .mask = H1_EV_TX_BODY, .name = "tx_body", .desc = "transmission of H1 body" },
#define H1_EV_TX_TLRS (1ULL << 16)
{ .mask = H1_EV_TX_TLRS, .name = "tx_trailerus", .desc = "transmission of H1 trailers" },
#define H1_EV_H1S_NEW (1ULL << 17)
{ .mask = H1_EV_H1S_NEW, .name = "h1s_new", .desc = "new H1 stream" },
#define H1_EV_H1S_BLK (1ULL << 18)
{ .mask = H1_EV_H1S_BLK, .name = "h1s_blk", .desc = "H1 stream blocked" },
#define H1_EV_H1S_END (1ULL << 19)
{ .mask = H1_EV_H1S_END, .name = "h1s_end", .desc = "H1 stream terminated" },
#define H1_EV_H1S_ERR (1ULL << 20)
{ .mask = H1_EV_H1S_ERR, .name = "h1s_err", .desc = "error on H1 stream" },
#define H1_EV_STRM_NEW (1ULL << 21)
{ .mask = H1_EV_STRM_NEW, .name = "strm_new", .desc = "app-layer stream creation" },
#define H1_EV_STRM_RECV (1ULL << 22)
{ .mask = H1_EV_STRM_RECV, .name = "strm_recv", .desc = "receiving data for stream" },
#define H1_EV_STRM_SEND (1ULL << 23)
{ .mask = H1_EV_STRM_SEND, .name = "strm_send", .desc = "sending data for stream" },
#define H1_EV_STRM_WAKE (1ULL << 24)
{ .mask = H1_EV_STRM_WAKE, .name = "strm_wake", .desc = "stream woken up" },
#define H1_EV_STRM_SHUT (1ULL << 25)
{ .mask = H1_EV_STRM_SHUT, .name = "strm_shut", .desc = "stream shutdown" },
#define H1_EV_STRM_END (1ULL << 26)
{ .mask = H1_EV_STRM_END, .name = "strm_end", .desc = "detaching app-layer stream" },
#define H1_EV_STRM_ERR (1ULL << 27)
{ .mask = H1_EV_STRM_ERR, .name = "strm_err", .desc = "stream error" },
{ }
};
static const struct name_desc h1_trace_lockon_args[4] = {
/* arg1 */ { /* already used by the connection */ },
/* arg2 */ { .name="h1s", .desc="H1 stream" },
/* arg3 */ { },
/* arg4 */ { }
};
static const struct name_desc h1_trace_decoding[] = {
#define H1_VERB_CLEAN 1
{ .name="clean", .desc="only user-friendly stuff, generally suitable for level \"user\"" },
#define H1_VERB_MINIMAL 2
{ .name="minimal", .desc="report only h1c/h1s state and flags, no real decoding" },
#define H1_VERB_SIMPLE 3
{ .name="simple", .desc="add request/response status line or htx info when available" },
#define H1_VERB_ADVANCED 4
{ .name="advanced", .desc="add header fields or frame decoding when available" },
#define H1_VERB_COMPLETE 5
{ .name="complete", .desc="add full data dump when available" },
{ /* end */ }
};
static struct trace_source trace_h1 __read_mostly = {
.name = IST("h1"),
.desc = "HTTP/1 multiplexer",
.arg_def = TRC_ARG1_CONN, // TRACE()'s first argument is always a connection
.default_cb = h1_trace,
.known_events = h1_trace_events,
.lockon_args = h1_trace_lockon_args,
.decoding = h1_trace_decoding,
.report_events = ~0, // report everything by default
};
#define TRACE_SOURCE &trace_h1
INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE);
/* the h1c and h1s pools */
DECLARE_STATIC_POOL(pool_head_h1c, "h1c", sizeof(struct h1c));
DECLARE_STATIC_POOL(pool_head_h1s, "h1s", sizeof(struct h1s));
static int h1_recv(struct h1c *h1c);
static int h1_send(struct h1c *h1c);
static int h1_process(struct h1c *h1c);
/* h1_io_cb is exported to see it resolved in "show fd" */
struct task *h1_io_cb(struct task *t, void *ctx, unsigned int state);
struct task *h1_timeout_task(struct task *t, void *context, unsigned int state);
static void h1_shutw_conn(struct connection *conn, enum cs_shw_mode mode);
static void h1_wake_stream_for_recv(struct h1s *h1s);
static void h1_wake_stream_for_send(struct h1s *h1s);
/* the H1 traces always expect that arg1, if non-null, is of type connection
* (from which we can derive h1c), that arg2, if non-null, is of type h1s, and
* that arg3, if non-null, is a htx for rx/tx headers.
*/
static void h1_trace(enum trace_level level, uint64_t mask, const struct trace_source *src,
const struct ist where, const struct ist func,
const void *a1, const void *a2, const void *a3, const void *a4)
{
const struct connection *conn = a1;
const struct h1c *h1c = conn ? conn->ctx : NULL;
const struct h1s *h1s = a2;
const struct htx *htx = a3;
const size_t *val = a4;
if (!h1c)
h1c = (h1s ? h1s->h1c : NULL);
if (!h1c || src->verbosity < H1_VERB_CLEAN)
return;
/* Display frontend/backend info by default */
chunk_appendf(&trace_buf, " : [%c]", ((h1c->flags & H1C_F_IS_BACK) ? 'B' : 'F'));
/* Display request and response states if h1s is defined */
if (h1s)
chunk_appendf(&trace_buf, " [%s, %s]",
h1m_state_str(h1s->req.state), h1m_state_str(h1s->res.state));
if (src->verbosity == H1_VERB_CLEAN)
return;
/* Display the value to the 4th argument (level > STATE) */
if (src->level > TRACE_LEVEL_STATE && val)
chunk_appendf(&trace_buf, " - VAL=%lu", (long)*val);
/* Display status-line if possible (verbosity > MINIMAL) */
if (src->verbosity > H1_VERB_MINIMAL && htx && htx_nbblks(htx)) {
const struct htx_blk *blk = htx_get_head_blk(htx);
const struct htx_sl *sl = htx_get_blk_ptr(htx, blk);
enum htx_blk_type type = htx_get_blk_type(blk);
if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL)
chunk_appendf(&trace_buf, " - \"%.*s %.*s %.*s\"",
HTX_SL_P1_LEN(sl), HTX_SL_P1_PTR(sl),
HTX_SL_P2_LEN(sl), HTX_SL_P2_PTR(sl),
HTX_SL_P3_LEN(sl), HTX_SL_P3_PTR(sl));
}
/* Display h1c info and, if defined, h1s info (pointer + flags) */
chunk_appendf(&trace_buf, " - h1c=%p(0x%08x)", h1c, h1c->flags);
if (h1s)
chunk_appendf(&trace_buf, " h1s=%p(0x%08x)", h1s, h1s->flags);
if (src->verbosity == H1_VERB_MINIMAL)
return;
/* Display input and output buffer info (level > USER & verbosity > SIMPLE) */
if (src->level > TRACE_LEVEL_USER) {
if (src->verbosity == H1_VERB_COMPLETE ||
(src->verbosity == H1_VERB_ADVANCED && (mask & (H1_EV_H1C_RECV|H1_EV_STRM_RECV))))
chunk_appendf(&trace_buf, " ibuf=%u@%p+%u/%u",
(unsigned int)b_data(&h1c->ibuf), b_orig(&h1c->ibuf),
(unsigned int)b_head_ofs(&h1c->ibuf), (unsigned int)b_size(&h1c->ibuf));
if (src->verbosity == H1_VERB_COMPLETE ||
(src->verbosity == H1_VERB_ADVANCED && (mask & (H1_EV_H1C_SEND|H1_EV_STRM_SEND))))
chunk_appendf(&trace_buf, " obuf=%u@%p+%u/%u",
(unsigned int)b_data(&h1c->obuf), b_orig(&h1c->obuf),
(unsigned int)b_head_ofs(&h1c->obuf), (unsigned int)b_size(&h1c->obuf));
}
/* Display htx info if defined (level > USER) */
if (src->level > TRACE_LEVEL_USER && htx) {
int full = 0;
/* Full htx info (level > STATE && verbosity > SIMPLE) */
if (src->level > TRACE_LEVEL_STATE) {
if (src->verbosity == H1_VERB_COMPLETE)
full = 1;
else if (src->verbosity == H1_VERB_ADVANCED && (mask & (H1_EV_RX_HDRS|H1_EV_TX_HDRS)))
full = 1;
}
chunk_memcat(&trace_buf, "\n\t", 2);
htx_dump(&trace_buf, htx, full);
}
}
/*****************************************************/
/* functions below are for dynamic buffer management */
/*****************************************************/
/*
* Indicates whether or not we may receive data. The rules are the following :
* - if an error or a shutdown for reads was detected on the connection we
* must not attempt to receive
* - if we are waiting for the connection establishment, we must not attempt
* to receive
* - if an error was detected on the stream we must not attempt to receive
* - if reads are explicitly disabled, we must not attempt to receive
* - if the input buffer failed to be allocated or is full , we must not try
* to receive
* - if the mux is not blocked on an input condition, we may attempt to receive
* - otherwise must may not attempt to receive
*/
static inline int h1_recv_allowed(const struct h1c *h1c)
{
if (h1c->flags & H1C_F_ST_ERROR) {
TRACE_DEVEL("recv not allowed because of error on h1c", H1_EV_H1C_RECV|H1_EV_H1C_BLK, h1c->conn);
return 0;
}
if (h1c->conn->flags & (CO_FL_ERROR|CO_FL_SOCK_RD_SH|CO_FL_WAIT_L4_CONN|CO_FL_WAIT_L6_CONN)) {
TRACE_DEVEL("recv not allowed because of (error|read0|waitl4|waitl6) on connection", H1_EV_H1C_RECV|H1_EV_H1C_BLK, h1c->conn);
return 0;
}
if (h1c->h1s && (h1c->h1s->flags & H1S_F_ERROR)) {
TRACE_DEVEL("recv not allowed because of error on h1s", H1_EV_H1C_RECV|H1_EV_H1C_BLK, h1c->conn);
return 0;
}
if (!(h1c->flags & (H1C_F_IN_ALLOC|H1C_F_IN_FULL|H1C_F_IN_SALLOC)))
return 1;
TRACE_DEVEL("recv not allowed because input is blocked", H1_EV_H1C_RECV|H1_EV_H1C_BLK, h1c->conn);
return 0;
}
/*
* Tries to grab a buffer and to re-enables processing on mux <target>. The h1
* flags are used to figure what buffer was requested. It returns 1 if the
* allocation succeeds, in which case the connection is woken up, or 0 if it's
* impossible to wake up and we prefer to be woken up later.
*/
static int h1_buf_available(void *target)
{
struct h1c *h1c = target;
if ((h1c->flags & H1C_F_IN_ALLOC) && b_alloc(&h1c->ibuf)) {
TRACE_STATE("unblocking h1c, ibuf allocated", H1_EV_H1C_RECV|H1_EV_H1C_BLK|H1_EV_H1C_WAKE, h1c->conn);
h1c->flags &= ~H1C_F_IN_ALLOC;
if (h1_recv_allowed(h1c))
tasklet_wakeup(h1c->wait_event.tasklet);
return 1;
}
if ((h1c->flags & H1C_F_OUT_ALLOC) && b_alloc(&h1c->obuf)) {
TRACE_STATE("unblocking h1s, obuf allocated", H1_EV_TX_DATA|H1_EV_H1S_BLK|H1_EV_STRM_WAKE, h1c->conn, h1c->h1s);
h1c->flags &= ~H1C_F_OUT_ALLOC;
if (h1c->h1s)
h1_wake_stream_for_send(h1c->h1s);
return 1;
}
if ((h1c->flags & H1C_F_IN_SALLOC) && h1c->h1s && b_alloc(&h1c->h1s->rxbuf)) {
TRACE_STATE("unblocking h1c, stream rxbuf allocated", H1_EV_H1C_RECV|H1_EV_H1C_BLK|H1_EV_H1C_WAKE, h1c->conn);
h1c->flags &= ~H1C_F_IN_SALLOC;
tasklet_wakeup(h1c->wait_event.tasklet);
return 1;
}
return 0;
}
/*
* Allocate a buffer. If if fails, it adds the mux in buffer wait queue.
*/
static inline struct buffer *h1_get_buf(struct h1c *h1c, struct buffer *bptr)
{
struct buffer *buf = NULL;
if (likely(!LIST_INLIST(&h1c->buf_wait.list)) &&
unlikely((buf = b_alloc(bptr)) == NULL)) {
h1c->buf_wait.target = h1c;
h1c->buf_wait.wakeup_cb = h1_buf_available;
LIST_APPEND(&ti->buffer_wq, &h1c->buf_wait.list);
}
return buf;
}
/*
* Release a buffer, if any, and try to wake up entities waiting in the buffer
* wait queue.
*/
static inline void h1_release_buf(struct h1c *h1c, struct buffer *bptr)
{
if (bptr->size) {
b_free(bptr);
offer_buffers(h1c->buf_wait.target, 1);
}
}
/* returns the number of streams in use on a connection to figure if it's idle
* or not. We rely on H1C_F_ST_IDLE to know if the connection is in-use or
* not. This flag is only set when no H1S is attached and when the previous
* stream, if any, was fully terminated without any error and in K/A mode.
*/
static int h1_used_streams(struct connection *conn)
{
struct h1c *h1c = conn->ctx;
return ((h1c->flags & H1C_F_ST_IDLE) ? 0 : 1);
}
/* returns the number of streams still available on a connection */
static int h1_avail_streams(struct connection *conn)
{
return 1 - h1_used_streams(conn);
}
/* Refresh the h1c task timeout if necessary */
static void h1_refresh_timeout(struct h1c *h1c)
{
if (h1c->task) {
if (!(h1c->flags & H1C_F_ST_ALIVE) || (h1c->flags & H1C_F_ST_SHUTDOWN)) {
/* half-closed or dead connections : switch to clientfin/serverfin
* timeouts so that we don't hang too long on clients that have
* gone away (especially in tunnel mode).
*/
h1c->task->expire = tick_add(now_ms, h1c->shut_timeout);
TRACE_DEVEL("refreshing connection's timeout (dead or half-closed)", H1_EV_H1C_SEND|H1_EV_H1C_RECV, h1c->conn);
}
else if (b_data(&h1c->obuf)) {
/* connection with pending outgoing data, need a timeout (server or client). */
h1c->task->expire = tick_add(now_ms, h1c->timeout);
TRACE_DEVEL("refreshing connection's timeout (pending outgoing data)", H1_EV_H1C_SEND|H1_EV_H1C_RECV, h1c->conn);
}
else if (!(h1c->flags & (H1C_F_IS_BACK|H1C_F_ST_READY))) {
/* front connections waiting for a fully usable stream need a timeout. */
h1c->task->expire = tick_add(now_ms, h1c->timeout);
TRACE_DEVEL("refreshing connection's timeout (alive front h1c but not ready)", H1_EV_H1C_SEND|H1_EV_H1C_RECV, h1c->conn);
}
else {
/* alive back connections of front connections with a conn-stream attached */
h1c->task->expire = TICK_ETERNITY;
TRACE_DEVEL("no connection timeout (alive back h1c or front h1c with a CS)", H1_EV_H1C_SEND|H1_EV_H1C_RECV, h1c->conn);
}
/* Finally set the idle expiration date if shorter */
h1c->task->expire = tick_first(h1c->task->expire, h1c->idle_exp);
TRACE_DEVEL("new expiration date", H1_EV_H1C_SEND|H1_EV_H1C_RECV, h1c->conn, 0, 0, (size_t[]){h1c->task->expire});
task_queue(h1c->task);
}
}
static void h1_set_idle_expiration(struct h1c *h1c)
{
if (h1c->flags & H1C_F_IS_BACK || !h1c->task) {
TRACE_DEVEL("no idle expiration (backend connection || no task)", H1_EV_H1C_RECV, h1c->conn);
h1c->idle_exp = TICK_ETERNITY;
return;
}
if (h1c->flags & H1C_F_ST_IDLE) {
if (!tick_isset(h1c->idle_exp)) {
if ((h1c->flags & H1C_F_WAIT_NEXT_REQ) && /* Not the first request */
!b_data(&h1c->ibuf) && /* No input data */
tick_isset(h1c->px->timeout.httpka)) { /* K-A timeout set */
h1c->idle_exp = tick_add_ifset(now_ms, h1c->px->timeout.httpka);
TRACE_DEVEL("set idle expiration (keep-alive timeout)", H1_EV_H1C_RECV, h1c->conn);
}
else {
h1c->idle_exp = tick_add_ifset(now_ms, h1c->px->timeout.httpreq);
TRACE_DEVEL("set idle expiration (http-request timeout)", H1_EV_H1C_RECV, h1c->conn);
}
}
}
else if ((h1c->flags & H1C_F_ST_ALIVE) && !(h1c->flags & H1C_F_ST_READY)) {
if (!tick_isset(h1c->idle_exp)) {
h1c->idle_exp = tick_add_ifset(now_ms, h1c->px->timeout.httpreq);
TRACE_DEVEL("set idle expiration (http-request timeout)", H1_EV_H1C_RECV, h1c->conn);
}
}
else { // CS_ATTACHED or SHUTDOWN
h1c->idle_exp = TICK_ETERNITY;
TRACE_DEVEL("unset idle expiration (attached || shutdown)", H1_EV_H1C_RECV, h1c->conn);
}
}
/*****************************************************************/
/* functions below are dedicated to the mux setup and management */
/*****************************************************************/
/* returns non-zero if there are input data pending for stream h1s. */
static inline size_t h1s_data_pending(const struct h1s *h1s)
{
const struct h1m *h1m;
h1m = ((h1s->h1c->flags & H1C_F_IS_BACK) ? &h1s->res : &h1s->req);
return ((h1m->state == H1_MSG_DONE) ? 0 : b_data(&h1s->h1c->ibuf));
}
/* Creates a new conn-stream and the associate stream. <input> is used as input
* buffer for the stream. On success, it is transferred to the stream and the
* mux is no longer responsible of it. On error, <input> is unchanged, thus the
* mux must still take care of it. However, there is nothing special to do
* because, on success, <input> is updated to points on BUF_NULL. Thus, calling
* b_free() on it is always safe. This function returns the conn-stream on
* success or NULL on error. */
static struct conn_stream *h1s_new_cs(struct h1s *h1s, struct buffer *input)
{
struct conn_stream *cs;
TRACE_ENTER(H1_EV_STRM_NEW, h1s->h1c->conn, h1s);
cs = cs_new(h1s->h1c->conn, h1s->h1c->conn->target);
if (!cs) {
TRACE_ERROR("CS allocation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1s->h1c->conn, h1s);
goto err;
}
h1s->cs = cs;
cs->ctx = h1s;
if (h1s->flags & H1S_F_NOT_FIRST)
cs->flags |= CS_FL_NOT_FIRST;
if (stream_create_from_cs(cs, input) < 0) {
TRACE_DEVEL("leaving on stream creation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1s->h1c->conn, h1s);
goto err;
}
h1s->h1c->flags = (h1s->h1c->flags & ~H1C_F_ST_EMBRYONIC) | H1C_F_ST_ATTACHED | H1C_F_ST_READY;
TRACE_LEAVE(H1_EV_STRM_NEW, h1s->h1c->conn, h1s);
return cs;
err:
cs_free(cs);
h1s->cs = NULL;
TRACE_DEVEL("leaving on error", H1_EV_STRM_NEW|H1_EV_STRM_ERR, h1s->h1c->conn, h1s);
return NULL;
}
static struct conn_stream *h1s_upgrade_cs(struct h1s *h1s, struct buffer *input)
{
TRACE_ENTER(H1_EV_STRM_NEW, h1s->h1c->conn, h1s);
if (stream_upgrade_from_cs(h1s->cs, input) < 0) {
TRACE_ERROR("stream upgrade failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1s->h1c->conn, h1s);
goto err;
}
h1s->h1c->flags |= H1C_F_ST_READY;
TRACE_LEAVE(H1_EV_STRM_NEW, h1s->h1c->conn, h1s);
return h1s->cs;
err:
TRACE_DEVEL("leaving on error", H1_EV_STRM_NEW|H1_EV_STRM_ERR, h1s->h1c->conn, h1s);
return NULL;
}
static struct h1s *h1s_new(struct h1c *h1c)
{
struct h1s *h1s;
TRACE_ENTER(H1_EV_H1S_NEW, h1c->conn);
h1s = pool_alloc(pool_head_h1s);
if (!h1s) {
TRACE_ERROR("H1S allocation failure", H1_EV_H1S_NEW|H1_EV_H1S_END|H1_EV_H1S_ERR, h1c->conn);
goto fail;
}
h1s->h1c = h1c;
h1c->h1s = h1s;
h1s->sess = NULL;
h1s->cs = NULL;
h1s->flags = H1S_F_WANT_KAL;
h1s->subs = NULL;
h1s->rxbuf = BUF_NULL;
memset(h1s->ws_key, 0, sizeof(h1s->ws_key));
h1m_init_req(&h1s->req);
h1s->req.flags |= (H1_MF_NO_PHDR|H1_MF_CLEAN_CONN_HDR);
h1m_init_res(&h1s->res);
h1s->res.flags |= (H1_MF_NO_PHDR|H1_MF_CLEAN_CONN_HDR);
h1s->status = 0;
h1s->meth = HTTP_METH_OTHER;
if (h1c->flags & H1C_F_WAIT_NEXT_REQ)
h1s->flags |= H1S_F_NOT_FIRST;
h1c->flags = (h1c->flags & ~(H1C_F_ST_IDLE|H1C_F_WAIT_NEXT_REQ)) | H1C_F_ST_EMBRYONIC;
TRACE_LEAVE(H1_EV_H1S_NEW, h1c->conn, h1s);
return h1s;
fail:
TRACE_DEVEL("leaving on error", H1_EV_STRM_NEW|H1_EV_STRM_ERR, h1c->conn);
return NULL;
}
static struct h1s *h1c_frt_stream_new(struct h1c *h1c)
{
struct session *sess = h1c->conn->owner;
struct h1s *h1s;
TRACE_ENTER(H1_EV_H1S_NEW, h1c->conn);
h1s = h1s_new(h1c);
if (!h1s)
goto fail;
h1s->sess = sess;
if (h1c->px->options2 & PR_O2_REQBUG_OK)
h1s->req.err_pos = -1;
h1c->idle_exp = TICK_ETERNITY;
h1_set_idle_expiration(h1c);
TRACE_LEAVE(H1_EV_H1S_NEW, h1c->conn, h1s);
return h1s;
fail:
TRACE_DEVEL("leaving on error", H1_EV_STRM_NEW|H1_EV_STRM_ERR, h1c->conn);
return NULL;
}
static struct h1s *h1c_bck_stream_new(struct h1c *h1c, struct conn_stream *cs, struct session *sess)
{
struct h1s *h1s;
TRACE_ENTER(H1_EV_H1S_NEW, h1c->conn);
h1s = h1s_new(h1c);
if (!h1s)
goto fail;
h1s->flags |= H1S_F_RX_BLK;
h1s->cs = cs;
h1s->sess = sess;
cs->ctx = h1s;
h1c->flags = (h1c->flags & ~H1C_F_ST_EMBRYONIC) | H1C_F_ST_ATTACHED | H1C_F_ST_READY;
if (h1c->px->options2 & PR_O2_RSPBUG_OK)
h1s->res.err_pos = -1;
TRACE_LEAVE(H1_EV_H1S_NEW, h1c->conn, h1s);
return h1s;
fail:
TRACE_DEVEL("leaving on error", H1_EV_STRM_NEW|H1_EV_STRM_ERR, h1c->conn);
return NULL;
}
static void h1s_destroy(struct h1s *h1s)
{
if (h1s) {
struct h1c *h1c = h1s->h1c;
TRACE_POINT(H1_EV_H1S_END, h1c->conn, h1s);
h1c->h1s = NULL;
if (h1s->subs)
h1s->subs->events = 0;
h1_release_buf(h1c, &h1s->rxbuf);
h1c->flags &= ~(H1C_F_WANT_SPLICE|
H1C_F_ST_EMBRYONIC|H1C_F_ST_ATTACHED|H1C_F_ST_READY|
H1C_F_OUT_FULL|H1C_F_OUT_ALLOC|H1C_F_IN_SALLOC|
H1C_F_CO_MSG_MORE|H1C_F_CO_STREAMER);
if (h1s->flags & H1S_F_ERROR) {
h1c->flags |= H1C_F_ST_ERROR;
TRACE_ERROR("h1s on error, set error on h1c", H1_EV_H1S_END|H1_EV_H1C_ERR, h1c->conn, h1s);
}
if (!(h1c->flags & (H1C_F_ST_ERROR|H1C_F_ST_SHUTDOWN)) && /* No error/shutdown on h1c */
!(h1c->conn->flags & (CO_FL_ERROR|CO_FL_SOCK_RD_SH|CO_FL_SOCK_WR_SH)) && /* No error/shutdown on conn */
(h1s->flags & H1S_F_WANT_KAL) && /* K/A possible */
h1s->req.state == H1_MSG_DONE && h1s->res.state == H1_MSG_DONE) { /* req/res in DONE state */
h1c->flags |= (H1C_F_ST_IDLE|H1C_F_WAIT_NEXT_REQ);
TRACE_STATE("set idle mode on h1c, waiting for the next request", H1_EV_H1C_ERR, h1c->conn, h1s);
}
else {
TRACE_STATE("set shudown on h1c", H1_EV_H1S_END, h1c->conn, h1s);
h1c->flags |= H1C_F_ST_SHUTDOWN;
}
pool_free(pool_head_h1s, h1s);
}
}
/*
* Initialize the mux once it's attached. It is expected that conn->ctx points
* to the existing conn_stream (for outgoing connections or for incoming ones
* during a mux upgrade) or NULL (for incoming ones during the connection
* establishment). <input> is always used as Input buffer and may contain
* data. It is the caller responsibility to not reuse it anymore. Returns < 0 on
* error.
*/
static int h1_init(struct connection *conn, struct proxy *proxy, struct session *sess,
struct buffer *input)
{
struct h1c *h1c;
struct task *t = NULL;
void *conn_ctx = conn->ctx;
TRACE_ENTER(H1_EV_H1C_NEW);
h1c = pool_alloc(pool_head_h1c);
if (!h1c) {
TRACE_ERROR("H1C allocation failure", H1_EV_H1C_NEW|H1_EV_H1C_END|H1_EV_H1C_ERR);
goto fail_h1c;
}
h1c->conn = conn;
h1c->px = proxy;
h1c->flags = H1C_F_ST_IDLE;
h1c->errcode = 0;
h1c->ibuf = *input;
h1c->obuf = BUF_NULL;
h1c->h1s = NULL;
h1c->task = NULL;
LIST_INIT(&h1c->buf_wait.list);
h1c->wait_event.tasklet = tasklet_new();
if (!h1c->wait_event.tasklet)
goto fail;
h1c->wait_event.tasklet->process = h1_io_cb;
h1c->wait_event.tasklet->context = h1c;
h1c->wait_event.events = 0;
h1c->idle_exp = TICK_ETERNITY;
if (conn_is_back(conn)) {
h1c->flags |= H1C_F_IS_BACK;
h1c->shut_timeout = h1c->timeout = proxy->timeout.server;
if (tick_isset(proxy->timeout.serverfin))
h1c->shut_timeout = proxy->timeout.serverfin;
} else {
h1c->shut_timeout = h1c->timeout = proxy->timeout.client;
if (tick_isset(proxy->timeout.clientfin))
h1c->shut_timeout = proxy->timeout.clientfin;
LIST_APPEND(&mux_stopping_data[tid].list,
&h1c->conn->stopping_list);
}
if (tick_isset(h1c->timeout)) {
t = task_new(tid_bit);
if (!t) {
TRACE_ERROR("H1C task allocation failure", H1_EV_H1C_NEW|H1_EV_H1C_END|H1_EV_H1C_ERR);
goto fail;
}
h1c->task = t;
t->process = h1_timeout_task;
t->context = h1c;
t->expire = tick_add(now_ms, h1c->timeout);
}
conn->ctx = h1c;
if (h1c->flags & H1C_F_IS_BACK) {
/* Create a new H1S now for backend connection only */
if (!h1c_bck_stream_new(h1c, conn_ctx, sess))
goto fail;
}
else if (conn_ctx) {
/* Upgraded frontend connection (from TCP) */
struct conn_stream *cs = conn_ctx;
if (!h1c_frt_stream_new(h1c))
goto fail;
h1c->h1s->cs = cs;
cs->ctx = h1c->h1s;
/* Attach the CS but Not ready yet */
h1c->flags = (h1c->flags & ~H1C_F_ST_EMBRYONIC) | H1C_F_ST_ATTACHED;
TRACE_DEVEL("Inherit the CS from TCP connection to perform an upgrade",
H1_EV_H1C_NEW|H1_EV_STRM_NEW, h1c->conn, h1c->h1s);
}
if (t) {
h1_set_idle_expiration(h1c);
t->expire = tick_first(t->expire, h1c->idle_exp);
task_queue(t);
}
/* prepare to read something */
if (b_data(&h1c->ibuf))
tasklet_wakeup(h1c->wait_event.tasklet);
else if (h1_recv_allowed(h1c))
h1c->conn->xprt->subscribe(h1c->conn, h1c->conn->xprt_ctx, SUB_RETRY_RECV, &h1c->wait_event);
/* mux->wake will be called soon to complete the operation */
TRACE_LEAVE(H1_EV_H1C_NEW, conn, h1c->h1s);
return 0;
fail:
task_destroy(t);
if (h1c->wait_event.tasklet)
tasklet_free(h1c->wait_event.tasklet);
pool_free(pool_head_h1c, h1c);
fail_h1c:
conn->ctx = conn_ctx; // restore saved context
TRACE_DEVEL("leaving in error", H1_EV_H1C_NEW|H1_EV_H1C_END|H1_EV_H1C_ERR);
return -1;
}
/* release function. This one should be called to free all resources allocated
* to the mux.
*/
static void h1_release(struct h1c *h1c)
{
struct connection *conn = NULL;
TRACE_POINT(H1_EV_H1C_END);
if (h1c) {
/* The connection must be aattached to this mux to be released */
if (h1c->conn && h1c->conn->ctx == h1c)
conn = h1c->conn;
TRACE_DEVEL("freeing h1c", H1_EV_H1C_END, conn);
if (conn && h1c->flags & H1C_F_UPG_H2C) {
TRACE_DEVEL("upgrading H1 to H2", H1_EV_H1C_END, conn);
/* Make sure we're no longer subscribed to anything */
if (h1c->wait_event.events)
conn->xprt->unsubscribe(conn, conn->xprt_ctx,
h1c->wait_event.events, &h1c->wait_event);
if (conn_upgrade_mux_fe(conn, NULL, &h1c->ibuf, ist("h2"), PROTO_MODE_HTTP) != -1) {
/* connection successfully upgraded to H2, this
* mux was already released */
return;
}
TRACE_ERROR("h2 upgrade failed", H1_EV_H1C_END|H1_EV_H1C_ERR, conn);
sess_log(conn->owner); /* Log if the upgrade failed */
}
if (LIST_INLIST(&h1c->buf_wait.list))
LIST_DEL_INIT(&h1c->buf_wait.list);
h1_release_buf(h1c, &h1c->ibuf);
h1_release_buf(h1c, &h1c->obuf);
if (h1c->task) {
h1c->task->context = NULL;
task_wakeup(h1c->task, TASK_WOKEN_OTHER);
h1c->task = NULL;
}
if (h1c->wait_event.tasklet)
tasklet_free(h1c->wait_event.tasklet);
h1s_destroy(h1c->h1s);
if (conn && h1c->wait_event.events != 0)
conn->xprt->unsubscribe(conn, conn->xprt_ctx, h1c->wait_event.events,
&h1c->wait_event);
pool_free(pool_head_h1c, h1c);
}
if (conn) {
if (!conn_is_back(conn))
LIST_DEL_INIT(&conn->stopping_list);
conn->mux = NULL;
conn->ctx = NULL;
TRACE_DEVEL("freeing conn", H1_EV_H1C_END, conn);
conn_stop_tracking(conn);
conn_full_close(conn);
if (conn->destroy_cb)
conn->destroy_cb(conn);
conn_free(conn);
}
}
/******************************************************/
/* functions below are for the H1 protocol processing */
/******************************************************/
/* Parse the request version and set H1_MF_VER_11 on <h1m> if the version is
* greater or equal to 1.1
*/
static void h1_parse_req_vsn(struct h1m *h1m, const struct htx_sl *sl)
{
const char *p = HTX_SL_REQ_VPTR(sl);
if ((HTX_SL_REQ_VLEN(sl) == 8) &&
(*(p + 5) > '1' ||
(*(p + 5) == '1' && *(p + 7) >= '1')))
h1m->flags |= H1_MF_VER_11;
}
/* Parse the response version and set H1_MF_VER_11 on <h1m> if the version is
* greater or equal to 1.1
*/
static void h1_parse_res_vsn(struct h1m *h1m, const struct htx_sl *sl)
{
const char *p = HTX_SL_RES_VPTR(sl);
if ((HTX_SL_RES_VLEN(sl) == 8) &&
(*(p + 5) > '1' ||
(*(p + 5) == '1' && *(p + 7) >= '1')))
h1m->flags |= H1_MF_VER_11;
}
/* Deduce the connection mode of the client connection, depending on the
* configuration and the H1 message flags. This function is called twice, the
* first time when the request is parsed and the second time when the response
* is parsed.
*/
static void h1_set_cli_conn_mode(struct h1s *h1s, struct h1m *h1m)
{
struct proxy *fe = h1s->h1c->px;
if (h1m->flags & H1_MF_RESP) {
/* Output direction: second pass */
if ((h1s->meth == HTTP_METH_CONNECT && h1s->status >= 200 && h1s->status < 300) ||
h1s->status == 101) {
/* Either we've established an explicit tunnel, or we're
* switching the protocol. In both cases, we're very unlikely to
* understand the next protocols. We have to switch to tunnel
* mode, so that we transfer the request and responses then let
* this protocol pass unmodified. When we later implement
* specific parsers for such protocols, we'll want to check the
* Upgrade header which contains information about that protocol
* for responses with status 101 (eg: see RFC2817 about TLS).
*/
h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_TUN;
TRACE_STATE("set tunnel mode (resp)", H1_EV_TX_DATA|H1_EV_TX_HDRS, h1s->h1c->conn, h1s);
}
else if (h1s->flags & H1S_F_WANT_KAL) {
/* By default the client is in KAL mode. CLOSE mode mean
* it is imposed by the client itself. So only change