• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jasonish / suricata / 22802647571

07 Mar 2026 04:23PM UTC coverage: 75.827% (-3.4%) from 79.233%
22802647571

push

github

jasonish
github-ci: add schema ordering check for yaml schema

253365 of 334137 relevant lines covered (75.83%)

3384729.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.22
/rust/src/http2/detect.rs
1
/* Copyright (C) 2020-2024 Open Information Security Foundation
2
 *
3
 * You can copy, redistribute or modify this Program under the terms of
4
 * the GNU General Public License version 2 as published by the Free
5
 * Software Foundation.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * version 2 along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
 * 02110-1301, USA.
16
 */
17

18
use super::http2::{
19
    HTTP2Event, HTTP2Frame, HTTP2FrameTypeData, HTTP2State, HTTP2Transaction, HTTP2TransactionState,
20
};
21
use super::parser;
22
use crate::detect::uint::{
23
    detect_match_uint, detect_parse_array_uint_enum, detect_uint_match_at_index,
24
    DetectUintArrayData, DetectUintData, DetectUintIndex, DetectUintMode,
25
};
26
use crate::detect::EnumString;
27
use crate::direction::Direction;
28
use base64::{engine::general_purpose::STANDARD, Engine};
29
use std::ffi::CStr;
30
use std::os::raw::c_void;
31
use std::rc::Rc;
32
use suricata_sys::sys::DetectEngineThreadCtx;
33

34
#[no_mangle]
35
pub unsafe extern "C" fn SCHttp2TxHasFrametype(
178✔
36
    tx: *mut std::os::raw::c_void, direction: u8, ctx: *const std::os::raw::c_void,
178✔
37
) -> std::os::raw::c_int {
178✔
38
    let tx = cast_pointer!(tx, HTTP2Transaction);
178✔
39
    let ctx = cast_pointer!(ctx, DetectUintArrayData<u8>);
178✔
40
    let frames = if direction & Direction::ToServer as u8 != 0 {
178✔
41
        &tx.frames_ts
89✔
42
    } else {
43
        &tx.frames_tc
89✔
44
    };
45
    return detect_uint_match_at_index::<HTTP2Frame, u8>(
178✔
46
        frames,
178✔
47
        ctx,
178✔
48
        |f| Some(f.header.ftype),
178✔
49
        tx.state >= HTTP2TransactionState::HTTP2StateClosed,
178✔
50
    );
178✔
51
}
178✔
52

53
#[no_mangle]
54
pub unsafe extern "C" fn SCHttp2ParseFrametype(
6✔
55
    str: *const std::os::raw::c_char,
6✔
56
) -> *mut std::os::raw::c_void {
6✔
57
    let ft_name: &CStr = CStr::from_ptr(str); //unsafe
6✔
58
    if let Ok(s) = ft_name.to_str() {
6✔
59
        if let Some(ctx) = detect_parse_array_uint_enum::<u8, parser::HTTP2FrameType>(s) {
6✔
60
            let boxed = Box::new(ctx);
6✔
61
            // DetectUintArrayData<u8> cannot be cbindgend
6✔
62
            return Box::into_raw(boxed) as *mut c_void;
6✔
63
        }
×
64
    }
×
65
    return std::ptr::null_mut();
×
66
}
6✔
67

68
fn http2_tx_get_errorcode(f: &HTTP2Frame) -> Option<u32> {
48✔
69
    match &f.data {
48✔
70
        HTTP2FrameTypeData::GOAWAY(goaway) => Some(goaway.errorcode),
16✔
71
        HTTP2FrameTypeData::RSTSTREAM(rst) => Some(rst.errorcode),
×
72
        _ => None,
32✔
73
    }
74
}
48✔
75

76
#[no_mangle]
77
pub unsafe extern "C" fn SCHttp2TxHasErrorCode(
48✔
78
    tx: *mut std::os::raw::c_void, direction: u8, ctx: *const std::os::raw::c_void,
48✔
79
) -> std::os::raw::c_int {
48✔
80
    let tx = cast_pointer!(tx, HTTP2Transaction);
48✔
81
    let ctx = cast_pointer!(ctx, DetectUintArrayData<u32>);
48✔
82
    let frames = if direction & Direction::ToServer as u8 != 0 {
48✔
83
        &tx.frames_ts
24✔
84
    } else {
85
        &tx.frames_tc
24✔
86
    };
87
    return detect_uint_match_at_index::<HTTP2Frame, u32>(
48✔
88
        frames,
48✔
89
        ctx,
48✔
90
        http2_tx_get_errorcode,
48✔
91
        tx.state >= HTTP2TransactionState::HTTP2StateClosed,
48✔
92
    );
48✔
93
}
48✔
94

95
#[no_mangle]
96
pub unsafe extern "C" fn SCHttp2ParseErrorCode(
5✔
97
    str: *const std::os::raw::c_char,
5✔
98
) -> *mut std::os::raw::c_void {
5✔
99
    let ft_name: &CStr = CStr::from_ptr(str); //unsafe
5✔
100
    if let Ok(s) = ft_name.to_str() {
5✔
101
        // special case for backward compatibility, now parsed as HTTP11_REQUIRED
102
        if s.to_uppercase() == "HTTP_1_1_REQUIRED" {
5✔
103
            let ctx = DetectUintArrayData::<u32> {
1✔
104
                du: DetectUintData {
1✔
105
                    arg1: parser::HTTP2ErrorCode::Http11Required.into_u(),
1✔
106
                    arg2: 0,
1✔
107
                    mode: DetectUintMode::DetectUintModeEqual,
1✔
108
                },
1✔
109
                index: DetectUintIndex::Any,
1✔
110
                start: 0,
1✔
111
                end: 0,
1✔
112
            };
1✔
113
            let boxed = Box::new(ctx);
1✔
114
            return Box::into_raw(boxed) as *mut c_void;
1✔
115
        }
4✔
116
        if let Some(ctx) = detect_parse_array_uint_enum::<u32, parser::HTTP2ErrorCode>(s) {
4✔
117
            let boxed = Box::new(ctx);
4✔
118
            return Box::into_raw(boxed) as *mut c_void;
4✔
119
        }
×
120
    }
×
121
    return std::ptr::null_mut();
×
122
}
5✔
123

124
fn get_http2_priority(frame: &HTTP2Frame) -> Option<u8> {
15✔
125
    return match &frame.data {
15✔
126
        HTTP2FrameTypeData::PRIORITY(prio) => Some(prio.weight),
×
127
        HTTP2FrameTypeData::HEADERS(hd) => {
4✔
128
            if let Some(prio) = hd.priority {
4✔
129
                return Some(prio.weight);
4✔
130
            }
×
131
            None
×
132
        }
133
        _ => None,
11✔
134
    };
135
}
15✔
136

137
fn http2_match_priority(
28✔
138
    tx: &HTTP2Transaction, direction: Direction, ctx: &DetectUintArrayData<u8>,
28✔
139
) -> std::os::raw::c_int {
28✔
140
    let frames = if direction == Direction::ToServer {
28✔
141
        &tx.frames_ts
14✔
142
    } else {
143
        &tx.frames_tc
14✔
144
    };
145
    let eof = tx.state >= HTTP2TransactionState::HTTP2StateClosed;
28✔
146
    return detect_uint_match_at_index::<HTTP2Frame, u8>(frames, ctx, get_http2_priority, eof);
28✔
147
}
28✔
148

149
#[no_mangle]
150
pub unsafe extern "C" fn SCHttp2PriorityMatch(
28✔
151
    tx: *mut std::os::raw::c_void, direction: u8, ctx: *const std::os::raw::c_void,
28✔
152
) -> std::os::raw::c_int {
28✔
153
    let tx = cast_pointer!(tx, HTTP2Transaction);
28✔
154
    let ctx = cast_pointer!(ctx, DetectUintArrayData<u8>);
28✔
155
    return http2_match_priority(tx, direction.into(), ctx);
28✔
156
}
28✔
157

158
fn get_http2_window(frame: &HTTP2Frame) -> Option<u32> {
1,605✔
159
    if let HTTP2FrameTypeData::WINDOWUPDATE(wu) = &frame.data {
1,605✔
160
        return Some(wu.sizeinc);
191✔
161
    }
1,414✔
162
    return None;
1,414✔
163
}
1,605✔
164

165
fn http2_match_window(
504✔
166
    tx: &HTTP2Transaction, direction: Direction, ctx: &DetectUintArrayData<u32>,
504✔
167
) -> std::os::raw::c_int {
504✔
168
    let frames = if direction == Direction::ToServer {
504✔
169
        &tx.frames_ts
252✔
170
    } else {
171
        &tx.frames_tc
252✔
172
    };
173
    let eof = tx.state >= HTTP2TransactionState::HTTP2StateClosed;
504✔
174
    return detect_uint_match_at_index::<HTTP2Frame, u32>(frames, ctx, get_http2_window, eof);
504✔
175
}
504✔
176

177
#[no_mangle]
178
pub unsafe extern "C" fn SCHttp2WindowMatch(
504✔
179
    tx: *mut std::os::raw::c_void, direction: u8, ctx: *const std::os::raw::c_void,
504✔
180
) -> std::os::raw::c_int {
504✔
181
    let tx = cast_pointer!(tx, HTTP2Transaction);
504✔
182
    let ctx = cast_pointer!(ctx, DetectUintArrayData<u32>);
504✔
183
    return http2_match_window(tx, direction.into(), ctx);
504✔
184
}
504✔
185

186
#[no_mangle]
187
pub unsafe extern "C" fn SCHttp2DetectSettingsCtxParse(
4✔
188
    str: *const std::os::raw::c_char,
4✔
189
) -> *mut std::os::raw::c_void {
4✔
190
    let ft_name: &CStr = CStr::from_ptr(str); //unsafe
4✔
191
    if let Ok(s) = ft_name.to_str() {
4✔
192
        if let Ok((_, ctx)) = parser::http2_parse_settingsctx(s) {
4✔
193
            let boxed = Box::new(ctx);
4✔
194
            return Box::into_raw(boxed) as *mut _;
4✔
195
        }
×
196
    }
×
197
    return std::ptr::null_mut();
×
198
}
4✔
199

200
#[no_mangle]
201
pub unsafe extern "C" fn SCHttp2DetectSettingsCtxFree(ctx: *mut std::os::raw::c_void) {
4✔
202
    // Just unbox...
4✔
203
    std::mem::drop(Box::from_raw(ctx as *mut parser::DetectHTTP2settingsSigCtx));
4✔
204
}
4✔
205

206
fn http2_detect_settings_match(
9✔
207
    set: &[parser::HTTP2FrameSettings], ctx: &parser::DetectHTTP2settingsSigCtx,
9✔
208
) -> std::os::raw::c_int {
9✔
209
    for e in set {
21✔
210
        if e.id == ctx.id {
15✔
211
            match &ctx.value {
6✔
212
                None => {
213
                    return 1;
×
214
                }
215
                Some(x) => {
6✔
216
                    if detect_match_uint(x, e.value) {
6✔
217
                        return 1;
3✔
218
                    }
3✔
219
                }
220
            }
221
        }
9✔
222
    }
223
    return 0;
6✔
224
}
9✔
225

226
fn http2_detect_settingsctx_match(
126✔
227
    ctx: &parser::DetectHTTP2settingsSigCtx, tx: &HTTP2Transaction, direction: Direction,
126✔
228
) -> std::os::raw::c_int {
126✔
229
    if direction == Direction::ToServer {
126✔
230
        for i in 0..tx.frames_ts.len() {
63✔
231
            if let HTTP2FrameTypeData::SETTINGS(set) = &tx.frames_ts[i].data {
60✔
232
                if http2_detect_settings_match(set, ctx) != 0 {
6✔
233
                    return 1;
3✔
234
                }
3✔
235
            }
54✔
236
        }
237
    } else {
238
        for i in 0..tx.frames_tc.len() {
63✔
239
            if let HTTP2FrameTypeData::SETTINGS(set) = &tx.frames_tc[i].data {
3✔
240
                if http2_detect_settings_match(set, ctx) != 0 {
3✔
241
                    return 1;
×
242
                }
3✔
243
            }
×
244
        }
245
    }
246
    return 0;
123✔
247
}
126✔
248

249
#[no_mangle]
250
pub unsafe extern "C" fn SCHttp2DetectSettingsCtxMatch(
126✔
251
    ctx: *const std::os::raw::c_void, tx: *mut std::os::raw::c_void, direction: u8,
126✔
252
) -> std::os::raw::c_int {
126✔
253
    let ctx = cast_pointer!(ctx, parser::DetectHTTP2settingsSigCtx);
126✔
254
    let tx = cast_pointer!(tx, HTTP2Transaction);
126✔
255
    return http2_detect_settingsctx_match(ctx, tx, direction.into());
126✔
256
}
126✔
257

258
fn http2_detect_sizeupdate_match(
×
259
    blocks: &[parser::HTTP2FrameHeaderBlock], ctx: &DetectUintData<u64>,
×
260
) -> std::os::raw::c_int {
×
261
    for block in blocks.iter() {
×
262
        if block.error == parser::HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeSizeUpdate
×
263
            && detect_match_uint(ctx, block.sizeupdate)
×
264
        {
265
            return 1;
×
266
        }
×
267
    }
268
    return 0;
×
269
}
×
270

271
fn http2_header_blocks(frame: &HTTP2Frame) -> Option<&[parser::HTTP2FrameHeaderBlock]> {
10,994✔
272
    match &frame.data {
10,994✔
273
        HTTP2FrameTypeData::HEADERS(hd) => {
3,177✔
274
            return Some(&hd.blocks);
3,177✔
275
        }
276
        HTTP2FrameTypeData::CONTINUATION(hd) => {
36✔
277
            return Some(&hd.blocks);
36✔
278
        }
279
        HTTP2FrameTypeData::PUSHPROMISE(hd) => {
×
280
            return Some(&hd.blocks);
×
281
        }
282
        _ => {}
7,781✔
283
    }
7,781✔
284
    return None;
7,781✔
285
}
10,994✔
286

287
fn http2_detect_sizeupdatectx_match(
×
288
    ctx: &DetectUintData<u64>, tx: &HTTP2Transaction, direction: Direction,
×
289
) -> std::os::raw::c_int {
×
290
    if direction == Direction::ToServer {
×
291
        for i in 0..tx.frames_ts.len() {
×
292
            if let Some(blocks) = http2_header_blocks(&tx.frames_ts[i]) {
×
293
                if http2_detect_sizeupdate_match(blocks, ctx) != 0 {
×
294
                    return 1;
×
295
                }
×
296
            }
×
297
        }
298
    } else {
299
        for i in 0..tx.frames_tc.len() {
×
300
            if let Some(blocks) = http2_header_blocks(&tx.frames_tc[i]) {
×
301
                if http2_detect_sizeupdate_match(blocks, ctx) != 0 {
×
302
                    return 1;
×
303
                }
×
304
            }
×
305
        }
306
    }
307
    return 0;
×
308
}
×
309

310
#[no_mangle]
311
pub unsafe extern "C" fn SCHttp2DetectSizeUpdateCtxMatch(
×
312
    ctx: *const std::os::raw::c_void, tx: *mut std::os::raw::c_void, direction: u8,
×
313
) -> std::os::raw::c_int {
×
314
    let ctx = cast_pointer!(ctx, DetectUintData<u64>);
×
315
    let tx = cast_pointer!(tx, HTTP2Transaction);
×
316
    return http2_detect_sizeupdatectx_match(ctx, tx, direction.into());
×
317
}
×
318

319
//TODOask better syntax between SCHttp2TxGetHeaderName in argument
320
// and SCHttp2DetectSizeUpdateCtxMatch explicitly casting
321
#[no_mangle]
322
pub unsafe extern "C" fn SCHttp2TxGetHeaderName(
×
323
    _de: *mut DetectEngineThreadCtx, tx: *const c_void, direction: u8, nb: u32,
×
324
    buffer: *mut *const u8, buffer_len: *mut u32,
×
325
) -> bool {
×
326
    let tx = cast_pointer!(tx, HTTP2Transaction);
×
327
    let mut pos = 0_u32;
×
328
    match direction.into() {
×
329
        Direction::ToServer => {
330
            for i in 0..tx.frames_ts.len() {
×
331
                if let Some(blocks) = http2_header_blocks(&tx.frames_ts[i]) {
×
332
                    if nb < pos + blocks.len() as u32 {
×
333
                        let value = &blocks[(nb - pos) as usize].name;
×
334
                        *buffer = value.as_ptr(); //unsafe
×
335
                        *buffer_len = value.len() as u32;
×
336
                        return true;
×
337
                    } else {
×
338
                        pos += blocks.len() as u32;
×
339
                    }
×
340
                }
×
341
            }
342
        }
343
        Direction::ToClient => {
344
            for i in 0..tx.frames_tc.len() {
×
345
                if let Some(blocks) = http2_header_blocks(&tx.frames_tc[i]) {
×
346
                    if nb < pos + blocks.len() as u32 {
×
347
                        let value = &blocks[(nb - pos) as usize].name;
×
348
                        *buffer = value.as_ptr(); //unsafe
×
349
                        *buffer_len = value.len() as u32;
×
350
                        return true;
×
351
                    } else {
×
352
                        pos += blocks.len() as u32;
×
353
                    }
×
354
                }
×
355
            }
356
        }
357
    }
358
    return false;
×
359
}
×
360

361
fn http2_frames_get_header_firstvalue<'a>(
1,258✔
362
    tx: &'a mut HTTP2Transaction, direction: Direction, name: &str,
1,258✔
363
) -> Result<&'a [u8], ()> {
1,258✔
364
    let frames = if direction == Direction::ToServer {
1,258✔
365
        &tx.frames_ts
895✔
366
    } else {
367
        &tx.frames_tc
363✔
368
    };
369
    for frame in frames {
1,682✔
370
        if let Some(blocks) = http2_header_blocks(frame) {
935✔
371
            for block in blocks.iter() {
910✔
372
                if block.name.as_ref() == name.as_bytes() {
910✔
373
                    return Ok(&block.value);
511✔
374
                }
399✔
375
            }
376
        }
397✔
377
    }
378
    return Err(());
747✔
379
}
1,258✔
380

381
// same as http2_frames_get_header_value but returns a new Vec
382
// instead of using the transaction to store the result slice
383
pub fn http2_frames_get_header_value_vec(
199✔
384
    tx: &HTTP2Transaction, direction: Direction, name: &str,
199✔
385
) -> Result<Vec<u8>, ()> {
199✔
386
    let mut found = 0;
199✔
387
    let mut vec = Vec::new();
199✔
388
    let frames = if direction == Direction::ToServer {
199✔
389
        &tx.frames_ts
24✔
390
    } else {
391
        &tx.frames_tc
175✔
392
    };
393
    for frame in frames {
741✔
394
        if let Some(blocks) = http2_header_blocks(frame) {
542✔
395
            for block in blocks.iter() {
1,832✔
396
                if block.name.as_ref() == name.as_bytes() {
1,832✔
397
                    if found == 0 {
36✔
398
                        vec.extend_from_slice(&block.value);
36✔
399
                        found = 1;
36✔
400
                    } else if found == 1 && Rc::strong_count(&block.name) <= 2 {
36✔
401
                        vec.extend_from_slice(b", ");
×
402
                        vec.extend_from_slice(&block.value);
×
403
                        found = 2;
×
404
                    } else if Rc::strong_count(&block.name) <= 2 {
×
405
                        vec.extend_from_slice(b", ");
×
406
                        vec.extend_from_slice(&block.value);
×
407
                    }
×
408
                }
1,796✔
409
            }
410
        }
175✔
411
    }
412
    if found == 0 {
199✔
413
        return Err(());
163✔
414
    } else {
415
        return Ok(vec);
36✔
416
    }
417
}
199✔
418

419
fn http2_frames_get_header_value<'a>(
2,710✔
420
    tx: &'a mut HTTP2Transaction, direction: Direction, name: &str,
2,710✔
421
) -> Result<&'a [u8], ()> {
2,710✔
422
    let mut found = 0;
2,710✔
423
    let mut vec = Vec::new();
2,710✔
424
    let mut single: Result<&[u8], ()> = Err(());
2,710✔
425
    let frames = if direction == Direction::ToServer {
2,710✔
426
        &tx.frames_ts
1,750✔
427
    } else {
428
        &tx.frames_tc
960✔
429
    };
430
    for frame in frames {
8,928✔
431
        if let Some(blocks) = http2_header_blocks(frame) {
6,218✔
432
            for block in blocks.iter() {
12,304✔
433
                if block.name.as_ref() == name.as_bytes() {
12,304✔
434
                    if found == 0 {
753✔
435
                        single = Ok(&block.value);
728✔
436
                        found = 1;
728✔
437
                    } else if found == 1 && Rc::strong_count(&block.name) <= 2 {
728✔
438
                        if let Ok(s) = single {
10✔
439
                            vec.extend_from_slice(s);
10✔
440
                        }
10✔
441
                        vec.extend_from_slice(b", ");
10✔
442
                        vec.extend_from_slice(&block.value);
10✔
443
                        found = 2;
10✔
444
                    } else if Rc::strong_count(&block.name) <= 2 {
15✔
445
                        vec.extend_from_slice(b", ");
3✔
446
                        vec.extend_from_slice(&block.value);
3✔
447
                    }
12✔
448
                }
11,551✔
449
            }
450
        }
4,687✔
451
    }
452
    if found == 0 {
2,710✔
453
        return Err(());
1,982✔
454
    } else if found == 1 {
728✔
455
        return single;
718✔
456
    } else {
457
        tx.escaped.push(vec);
10✔
458
        let idx = tx.escaped.len() - 1;
10✔
459
        let value = &tx.escaped[idx];
10✔
460
        return Ok(value);
10✔
461
    }
462
}
2,710✔
463

464
// we mutate the tx to cache req_line
465
fn http2_tx_get_req_line(tx: &mut HTTP2Transaction) {
174✔
466
    if !tx.req_line.is_empty() {
174✔
467
        return;
5✔
468
    }
169✔
469
    let empty = Vec::new();
169✔
470
    let mut req_line = Vec::new();
169✔
471
    let method =
169✔
472
        if let Ok(value) = http2_frames_get_header_firstvalue(tx, Direction::ToServer, ":method") {
169✔
473
            value
66✔
474
        } else {
475
            &empty
103✔
476
        };
477
    req_line.extend(method);
169✔
478
    req_line.push(b' ');
169✔
479

480
    let uri =
169✔
481
        if let Ok(value) = http2_frames_get_header_firstvalue(tx, Direction::ToServer, ":path") {
169✔
482
            value
66✔
483
        } else {
484
            &empty
103✔
485
        };
486
    req_line.extend(uri);
169✔
487
    req_line.extend(b" HTTP/2\r\n");
169✔
488
    tx.req_line.extend(req_line)
169✔
489
}
174✔
490

491
#[no_mangle]
492
pub unsafe extern "C" fn SCHttp2TxGetRequestLine(
174✔
493
    tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
174✔
494
) -> u8 {
174✔
495
    http2_tx_get_req_line(tx);
174✔
496
    *buffer = tx.req_line.as_ptr(); //unsafe
174✔
497
    *buffer_len = tx.req_line.len() as u32;
174✔
498
    return 1;
174✔
499
}
174✔
500

501
fn http2_tx_get_resp_line(tx: &mut HTTP2Transaction) {
194✔
502
    if !tx.resp_line.is_empty() {
194✔
503
        return;
25✔
504
    }
169✔
505
    let empty = Vec::new();
169✔
506
    let mut resp_line: Vec<u8> = Vec::new();
169✔
507

508
    let status =
169✔
509
        if let Ok(value) = http2_frames_get_header_firstvalue(tx, Direction::ToClient, ":status") {
169✔
510
            value
66✔
511
        } else {
512
            &empty
103✔
513
        };
514
    resp_line.extend(b"HTTP/2 ");
169✔
515
    resp_line.extend(status);
169✔
516
    resp_line.extend(b"\r\n");
169✔
517
    tx.resp_line.extend(resp_line)
169✔
518
}
194✔
519

520
#[no_mangle]
521
pub unsafe extern "C" fn SCHttp2TxGetResponseLine(
194✔
522
    tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
194✔
523
) -> u8 {
194✔
524
    http2_tx_get_resp_line(tx);
194✔
525
    *buffer = tx.resp_line.as_ptr(); //unsafe
194✔
526
    *buffer_len = tx.resp_line.len() as u32;
194✔
527
    return 1;
194✔
528
}
194✔
529

530
#[no_mangle]
531
pub unsafe extern "C" fn SCHttp2TxGetUri(
383✔
532
    tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
383✔
533
) -> u8 {
383✔
534
    if let Ok(value) = http2_frames_get_header_firstvalue(tx, Direction::ToServer, ":path") {
383✔
535
        *buffer = value.as_ptr(); //unsafe
151✔
536
        *buffer_len = value.len() as u32;
151✔
537
        return 1;
151✔
538
    }
232✔
539
    return 0;
232✔
540
}
383✔
541

542
#[no_mangle]
543
pub unsafe extern "C" fn SCHttp2TxGetMethod(
174✔
544
    tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
174✔
545
) -> u8 {
174✔
546
    if let Ok(value) = http2_frames_get_header_firstvalue(tx, Direction::ToServer, ":method") {
174✔
547
        *buffer = value.as_ptr(); //unsafe
71✔
548
        *buffer_len = value.len() as u32;
71✔
549
        return 1;
71✔
550
    }
103✔
551
    return 0;
103✔
552
}
174✔
553

554
#[no_mangle]
555
pub unsafe extern "C" fn SCHttp2TxGetHost(
34✔
556
    tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
34✔
557
) -> u8 {
34✔
558
    if let Ok(value) = http2_frames_get_header_value(tx, Direction::ToServer, ":authority") {
34✔
559
        *buffer = value.as_ptr(); //unsafe
11✔
560
        *buffer_len = value.len() as u32;
11✔
561
        return 1;
11✔
562
    }
23✔
563
    return 0;
23✔
564
}
34✔
565

566
fn http2_lower(value: &[u8]) -> Option<Vec<u8>> {
143✔
567
    for i in 0..value.len() {
2,573✔
568
        if value[i].is_ascii_uppercase() {
2,573✔
569
            // we got at least one upper character, need to transform
570
            let mut vec: Vec<u8> = Vec::with_capacity(value.len());
×
571
            vec.extend_from_slice(value);
×
572
            for e in &mut vec {
×
573
                e.make_ascii_lowercase();
×
574
            }
×
575
            return Some(vec);
×
576
        }
2,573✔
577
    }
578
    return None;
143✔
579
}
143✔
580

581
// returns a tuple with the value and its size
582
fn http2_normalize_host(value: &[u8]) -> &[u8] {
148✔
583
    match value.iter().position(|&x| x == b'@') {
2,870✔
584
        Some(i) => {
4✔
585
            let value = &value[i + 1..];
4✔
586
            match value.iter().position(|&x| x == b':') {
39✔
587
                Some(i) => {
1✔
588
                    return &value[..i];
1✔
589
                }
590
                None => {
591
                    return value;
3✔
592
                }
593
            }
594
        }
595
        None => match value.iter().position(|&x| x == b':') {
2,618✔
596
            Some(i) => {
41✔
597
                return &value[..i];
41✔
598
            }
599
            None => {
600
                return value;
103✔
601
            }
602
        },
603
    }
604
}
148✔
605

606
#[no_mangle]
607
pub unsafe extern "C" fn SCHttp2TxGetHostNorm(
350✔
608
    tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
350✔
609
) -> u8 {
350✔
610
    if let Ok(value) = http2_frames_get_header_value(tx, Direction::ToServer, ":authority") {
350✔
611
        let r = http2_normalize_host(value);
143✔
612
        // r is a tuple with the value and its size
143✔
613
        // this is useful when we only take a substring (before the port)
143✔
614
        match http2_lower(r) {
143✔
615
            Some(normval) => {
×
616
                // In case we needed some normalization,
×
617
                // the transaction needs to take ownership of this normalized host
×
618
                tx.escaped.push(normval);
×
619
                let idx = tx.escaped.len() - 1;
×
620
                let resvalue = &tx.escaped[idx];
×
621
                *buffer = resvalue.as_ptr(); //unsafe
×
622
                *buffer_len = resvalue.len() as u32;
×
623
                return 1;
×
624
            }
625
            None => {
626
                *buffer = r.as_ptr(); //unsafe
143✔
627
                *buffer_len = r.len() as u32;
143✔
628
                return 1;
143✔
629
            }
630
        }
631
    }
207✔
632
    return 0;
207✔
633
}
350✔
634

635
#[no_mangle]
636
pub unsafe extern "C" fn SCHttp2TxGetUserAgent(
174✔
637
    tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
174✔
638
) -> u8 {
174✔
639
    if let Ok(value) = http2_frames_get_header_value(tx, Direction::ToServer, "user-agent") {
174✔
640
        *buffer = value.as_ptr(); //unsafe
66✔
641
        *buffer_len = value.len() as u32;
66✔
642
        return 1;
66✔
643
    }
108✔
644
    return 0;
108✔
645
}
174✔
646

647
#[no_mangle]
648
pub unsafe extern "C" fn SCHttp2TxGetStatus(
194✔
649
    tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32,
194✔
650
) -> u8 {
194✔
651
    if let Ok(value) = http2_frames_get_header_firstvalue(tx, Direction::ToClient, ":status") {
194✔
652
        *buffer = value.as_ptr(); //unsafe
91✔
653
        *buffer_len = value.len() as u32;
91✔
654
        return 1;
91✔
655
    }
103✔
656
    return 0;
103✔
657
}
194✔
658

659
#[no_mangle]
660
pub unsafe extern "C" fn SCHttp2TxGetCookie(
384✔
661
    tx: &mut HTTP2Transaction, direction: u8, buffer: *mut *const u8, buffer_len: *mut u32,
384✔
662
) -> u8 {
384✔
663
    if direction == u8::from(Direction::ToServer) {
384✔
664
        if let Ok(value) = http2_frames_get_header_value(tx, Direction::ToServer, "cookie") {
182✔
665
            *buffer = value.as_ptr(); //unsafe
13✔
666
            *buffer_len = value.len() as u32;
13✔
667
            return 1;
13✔
668
        }
169✔
669
    } else if let Ok(value) = http2_frames_get_header_value(tx, Direction::ToClient, "set-cookie") {
202✔
670
        *buffer = value.as_ptr(); //unsafe
1✔
671
        *buffer_len = value.len() as u32;
1✔
672
        return 1;
1✔
673
    }
201✔
674
    return 0;
370✔
675
}
384✔
676

677
#[no_mangle]
678
pub unsafe extern "C" fn SCHttp2TxGetHeaderValue(
1,767✔
679
    tx: &mut HTTP2Transaction, direction: u8, strname: *const std::os::raw::c_char,
1,767✔
680
    buffer: *mut *const u8, buffer_len: *mut u32,
1,767✔
681
) -> u8 {
1,767✔
682
    let hname: &CStr = CStr::from_ptr(strname); //unsafe
1,767✔
683
    if let Ok(s) = hname.to_str() {
1,767✔
684
        if let Ok(value) = http2_frames_get_header_value(tx, direction.into(), &s.to_lowercase()) {
1,767✔
685
            *buffer = value.as_ptr(); //unsafe
493✔
686
            *buffer_len = value.len() as u32;
493✔
687
            return 1;
493✔
688
        }
1,274✔
689
    }
×
690
    return 0;
1,274✔
691
}
1,767✔
692

693
fn http2_escape_header(blocks: &[parser::HTTP2FrameHeaderBlock], i: u32) -> Vec<u8> {
59✔
694
    //minimum size + 2 for escapes
59✔
695
    let normalsize = blocks[i as usize].value.len() + 2 + blocks[i as usize].name.len();
59✔
696
    let mut vec = Vec::with_capacity(normalsize);
59✔
697
    vec.extend_from_slice(&blocks[i as usize].name);
59✔
698
    vec.extend_from_slice(b": ");
59✔
699
    vec.extend_from_slice(&blocks[i as usize].value);
59✔
700
    return vec;
59✔
701
}
59✔
702

703
#[no_mangle]
704
pub unsafe extern "C" fn SCHttp2TxGetHeaderNames(
440✔
705
    tx: &mut HTTP2Transaction, direction: u8, buffer: *mut *const u8, buffer_len: *mut u32,
440✔
706
) -> u8 {
440✔
707
    let mut vec = vec![b'\r', b'\n'];
440✔
708
    let frames = if direction & Direction::ToServer as u8 != 0 {
440✔
709
        &tx.frames_ts
210✔
710
    } else {
711
        &tx.frames_tc
230✔
712
    };
713
    for frame in frames {
1,549✔
714
        if let Some(blocks) = http2_header_blocks(frame) {
1,109✔
715
            for block in blocks.iter() {
1,729✔
716
                // we do not escape linefeeds in headers names
1,729✔
717
                vec.extend_from_slice(&block.name);
1,729✔
718
                vec.extend_from_slice(b"\r\n");
1,729✔
719
            }
1,729✔
720
        }
851✔
721
    }
722
    if vec.len() > 2 {
440✔
723
        vec.extend_from_slice(b"\r\n");
174✔
724
        tx.escaped.push(vec);
174✔
725
        let idx = tx.escaped.len() - 1;
174✔
726
        let value = &tx.escaped[idx];
174✔
727
        *buffer = value.as_ptr(); //unsafe
174✔
728
        *buffer_len = value.len() as u32;
174✔
729
        return 1;
174✔
730
    }
266✔
731
    return 0;
266✔
732
}
440✔
733

734
fn http2_header_iscookie(direction: Direction, hname: &[u8]) -> bool {
1,729✔
735
    if let Ok(s) = std::str::from_utf8(hname) {
1,729✔
736
        if direction == Direction::ToServer {
1,729✔
737
            if s.to_lowercase() == "cookie" {
860✔
738
                return true;
26✔
739
            }
834✔
740
        } else if s.to_lowercase() == "set-cookie" {
869✔
741
            return true;
1✔
742
        }
868✔
743
    }
×
744
    return false;
1,702✔
745
}
1,729✔
746

747
fn http2_header_trimspaces(value: &[u8]) -> &[u8] {
1,705✔
748
    let mut start = 0;
1,705✔
749
    let mut end = value.len();
1,705✔
750
    while start < value.len() {
1,708✔
751
        if value[start] == b' ' || value[start] == b'\t' {
1,686✔
752
            start += 1;
3✔
753
        } else {
3✔
754
            break;
1,683✔
755
        }
756
    }
757
    while end > start {
1,706✔
758
        if value[end - 1] == b' ' || value[end - 1] == b'\t' {
1,684✔
759
            end -= 1;
1✔
760
        } else {
1✔
761
            break;
1,683✔
762
        }
763
    }
764
    return &value[start..end];
1,705✔
765
}
1,705✔
766

767
#[no_mangle]
768
pub unsafe extern "C" fn SCHttp2TxGetHeaders(
440✔
769
    tx: &mut HTTP2Transaction, direction: u8, buffer: *mut *const u8, buffer_len: *mut u32,
440✔
770
) -> u8 {
440✔
771
    let mut vec = Vec::new();
440✔
772
    let frames = if direction & Direction::ToServer as u8 != 0 {
440✔
773
        &tx.frames_ts
210✔
774
    } else {
775
        &tx.frames_tc
230✔
776
    };
777
    for frame in frames {
1,549✔
778
        if let Some(blocks) = http2_header_blocks(frame) {
1,109✔
779
            for block in blocks.iter() {
1,729✔
780
                if !http2_header_iscookie(direction.into(), &block.name) {
1,729✔
781
                    // we do not escape linefeeds nor : in headers names
1,702✔
782
                    vec.extend_from_slice(&block.name);
1,702✔
783
                    vec.extend_from_slice(b": ");
1,702✔
784
                    vec.extend_from_slice(http2_header_trimspaces(&block.value));
1,702✔
785
                    vec.extend_from_slice(b"\r\n");
1,702✔
786
                }
1,702✔
787
            }
788
        }
851✔
789
    }
790
    if !vec.is_empty() {
440✔
791
        tx.escaped.push(vec);
174✔
792
        let idx = tx.escaped.len() - 1;
174✔
793
        let value = &tx.escaped[idx];
174✔
794
        *buffer = value.as_ptr(); //unsafe
174✔
795
        *buffer_len = value.len() as u32;
174✔
796
        return 1;
174✔
797
    }
266✔
798
    return 0;
266✔
799
}
440✔
800

801
#[no_mangle]
802
pub unsafe extern "C" fn SCHttp2TxGetHeadersRaw(
356✔
803
    tx: &mut HTTP2Transaction, direction: u8, buffer: *mut *const u8, buffer_len: *mut u32,
356✔
804
) -> u8 {
356✔
805
    let mut vec = Vec::new();
356✔
806
    let frames = if direction & Direction::ToServer as u8 != 0 {
356✔
807
        &tx.frames_ts
168✔
808
    } else {
809
        &tx.frames_tc
188✔
810
    };
811
    for frame in frames {
1,353✔
812
        if let Some(blocks) = http2_header_blocks(frame) {
997✔
813
            for block in blocks.iter() {
1,602✔
814
                // we do not escape linefeeds nor : in headers names
1,602✔
815
                vec.extend_from_slice(&block.name);
1,602✔
816
                vec.extend_from_slice(b": ");
1,602✔
817
                vec.extend_from_slice(&block.value);
1,602✔
818
                vec.extend_from_slice(b"\r\n");
1,602✔
819
            }
1,602✔
820
        }
803✔
821
    }
822
    if !vec.is_empty() {
356✔
823
        tx.escaped.push(vec);
158✔
824
        let idx = tx.escaped.len() - 1;
158✔
825
        let value = &tx.escaped[idx];
158✔
826
        *buffer = value.as_ptr(); //unsafe
158✔
827
        *buffer_len = value.len() as u32;
158✔
828
        return 1;
158✔
829
    }
198✔
830
    return 0;
198✔
831
}
356✔
832

833
#[no_mangle]
834
pub unsafe extern "C" fn SCHttp2TxGetHeader(
89✔
835
    _de: *mut DetectEngineThreadCtx, tx: *const c_void, direction: u8, nb: u32,
89✔
836
    buffer: *mut *const u8, buffer_len: *mut u32,
89✔
837
) -> bool {
89✔
838
    let tx = cast_pointer!(tx, HTTP2Transaction);
89✔
839
    let mut pos = 0_u32;
89✔
840
    match direction.into() {
89✔
841
        Direction::ToServer => {
842
            for i in 0..tx.frames_ts.len() {
89✔
843
                if let Some(blocks) = http2_header_blocks(&tx.frames_ts[i]) {
84✔
844
                    if nb < pos + blocks.len() as u32 {
67✔
845
                        let ehdr = http2_escape_header(blocks, nb - pos);
59✔
846
                        tx.escaped.push(ehdr);
59✔
847
                        let idx = tx.escaped.len() - 1;
59✔
848
                        let value = &tx.escaped[idx];
59✔
849
                        *buffer = value.as_ptr(); //unsafe
59✔
850
                        *buffer_len = value.len() as u32;
59✔
851
                        return true;
59✔
852
                    } else {
8✔
853
                        pos += blocks.len() as u32;
8✔
854
                    }
8✔
855
                }
17✔
856
            }
857
        }
858
        Direction::ToClient => {
859
            for i in 0..tx.frames_tc.len() {
×
860
                if let Some(blocks) = http2_header_blocks(&tx.frames_tc[i]) {
×
861
                    if nb < pos + blocks.len() as u32 {
×
862
                        let ehdr = http2_escape_header(blocks, nb - pos);
×
863
                        tx.escaped.push(ehdr);
×
864
                        let idx = tx.escaped.len() - 1;
×
865
                        let value = &tx.escaped[idx];
×
866
                        *buffer = value.as_ptr(); //unsafe
×
867
                        *buffer_len = value.len() as u32;
×
868
                        return true;
×
869
                    } else {
×
870
                        pos += blocks.len() as u32;
×
871
                    }
×
872
                }
×
873
            }
874
        }
875
    }
876
    return false;
30✔
877
}
89✔
878

879
fn http2_tx_set_header(state: &mut HTTP2State, name: &[u8], input: &[u8]) {
155✔
880
    let head = parser::HTTP2FrameHeader {
155✔
881
        length: 0,
155✔
882
        ftype: parser::HTTP2FrameType::Headers as u8,
155✔
883
        flags: 0,
155✔
884
        reserved: 0,
155✔
885
        stream_id: 1,
155✔
886
    };
155✔
887
    let mut blocks = Vec::new();
155✔
888
    let b = parser::HTTP2FrameHeaderBlock {
155✔
889
        name: Rc::new(name.to_vec()),
155✔
890
        value: Rc::new(input.to_vec()),
155✔
891
        error: parser::HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeSuccess,
155✔
892
        sizeupdate: 0,
155✔
893
    };
155✔
894
    blocks.push(b);
155✔
895
    let hs = parser::HTTP2FrameHeaders {
155✔
896
        padlength: None,
155✔
897
        priority: None,
155✔
898
        blocks,
155✔
899
    };
155✔
900
    let txdata = HTTP2FrameTypeData::HEADERS(hs);
155✔
901
    let tx = state
155✔
902
        .find_or_create_tx(&head, &txdata, Direction::ToServer)
155✔
903
        .unwrap();
155✔
904
    tx.frames_ts.push(HTTP2Frame {
155✔
905
        header: head,
155✔
906
        data: txdata,
155✔
907
    });
155✔
908
    //we do not expect more data from client
155✔
909
    tx.state = HTTP2TransactionState::HTTP2StateHalfClosedClient;
155✔
910
}
155✔
911

912
#[no_mangle]
913
pub unsafe extern "C" fn SCHttp2TxSetMethod(
21✔
914
    state: &mut HTTP2State, buffer: *const u8, buffer_len: u32,
21✔
915
) {
21✔
916
    let slice = build_slice!(buffer, buffer_len as usize);
21✔
917
    http2_tx_set_header(state, ":method".as_bytes(), slice)
21✔
918
}
21✔
919

920
#[no_mangle]
921
pub unsafe extern "C" fn SCHttp2TxSetUri(
21✔
922
    state: &mut HTTP2State, buffer: *const u8, buffer_len: u32,
21✔
923
) {
21✔
924
    let slice = build_slice!(buffer, buffer_len as usize);
21✔
925
    http2_tx_set_header(state, ":path".as_bytes(), slice)
21✔
926
}
21✔
927

928
fn http2_tx_set_settings(state: &mut HTTP2State, input: &[u8]) {
19✔
929
    match STANDARD.decode(input) {
19✔
930
        Ok(dec) => {
19✔
931
            if dec.len() % 6 != 0 {
19✔
932
                state.set_event(HTTP2Event::InvalidHttp1Settings);
×
933
            }
19✔
934

935
            let head = parser::HTTP2FrameHeader {
19✔
936
                length: dec.len() as u32,
19✔
937
                ftype: parser::HTTP2FrameType::Settings as u8,
19✔
938
                flags: 0,
19✔
939
                reserved: 0,
19✔
940
                stream_id: 0,
19✔
941
            };
19✔
942

19✔
943
            match parser::http2_parse_frame_settings(&dec) {
19✔
944
                Ok((_, set)) => {
19✔
945
                    let txdata = HTTP2FrameTypeData::SETTINGS(set);
19✔
946
                    let tx = state
19✔
947
                        .find_or_create_tx(&head, &txdata, Direction::ToServer)
19✔
948
                        .unwrap();
19✔
949
                    tx.frames_ts.push(HTTP2Frame {
19✔
950
                        header: head,
19✔
951
                        data: txdata,
19✔
952
                    });
19✔
953
                }
19✔
954
                Err(_) => {
×
955
                    state.set_event(HTTP2Event::InvalidHttp1Settings);
×
956
                }
×
957
            }
958
        }
959
        Err(_) => {
×
960
            state.set_event(HTTP2Event::InvalidHttp1Settings);
×
961
        }
×
962
    }
963
}
19✔
964

965
fn http2_caseinsensitive_cmp(s1: &[u8], s2: &str) -> bool {
113✔
966
    if let Ok(s) = std::str::from_utf8(s1) {
113✔
967
        return s.to_lowercase() == s2;
113✔
968
    }
×
969
    return false;
×
970
}
113✔
971

972
#[no_mangle]
973
pub unsafe extern "C" fn SCHttp2TxAddHeader(
132✔
974
    state: &mut HTTP2State, name: *const u8, name_len: u32, value: *const u8, value_len: u32,
132✔
975
) {
132✔
976
    let slice_name = build_slice!(name, name_len as usize);
132✔
977
    let slice_value = build_slice!(value, value_len as usize);
132✔
978
    if slice_name == "HTTP2-Settings".as_bytes() {
132✔
979
        http2_tx_set_settings(state, slice_value)
19✔
980
    } else if http2_caseinsensitive_cmp(slice_name, "host") {
113✔
981
        http2_tx_set_header(state, ":authority".as_bytes(), slice_value)
21✔
982
    } else {
983
        http2_tx_set_header(state, slice_name, slice_value)
92✔
984
    }
985
}
132✔
986

987
#[cfg(test)]
988
mod tests {
989

990
    use super::*;
991

992
    #[test]
993
    fn test_http2_normalize_host() {
1✔
994
        let buf0 = "aBC.com:1234".as_bytes();
1✔
995
        let r0 = http2_normalize_host(buf0);
1✔
996
        assert_eq!(r0, "aBC.com".as_bytes().to_vec());
1✔
997
        let buf1 = "oisf.net".as_bytes();
1✔
998
        let r1 = http2_normalize_host(buf1);
1✔
999
        assert_eq!(r1, "oisf.net".as_bytes().to_vec());
1✔
1000
        let buf2 = "localhost:3000".as_bytes();
1✔
1001
        let r2 = http2_normalize_host(buf2);
1✔
1002
        assert_eq!(r2, "localhost".as_bytes().to_vec());
1✔
1003
        let buf3 = "user:pass@localhost".as_bytes();
1✔
1004
        let r3 = http2_normalize_host(buf3);
1✔
1005
        assert_eq!(r3, "localhost".as_bytes().to_vec());
1✔
1006
        let buf4 = "user:pass@localhost:123".as_bytes();
1✔
1007
        let r4 = http2_normalize_host(buf4);
1✔
1008
        assert_eq!(r4, "localhost".as_bytes().to_vec());
1✔
1009
    }
1✔
1010

1011
    #[test]
1012
    fn test_http2_header_trimspaces() {
1✔
1013
        let buf0 = "nospaces".as_bytes();
1✔
1014
        let r0 = http2_header_trimspaces(buf0);
1✔
1015
        assert_eq!(r0, "nospaces".as_bytes());
1✔
1016
        let buf1 = " spaces\t".as_bytes();
1✔
1017
        let r1 = http2_header_trimspaces(buf1);
1✔
1018
        assert_eq!(r1, "spaces".as_bytes());
1✔
1019
        let buf2 = " \t".as_bytes();
1✔
1020
        let r2 = http2_header_trimspaces(buf2);
1✔
1021
        assert_eq!(r2, "".as_bytes());
1✔
1022
    }
1✔
1023

1024
    #[test]
1025
    fn test_http2_frames_get_header_value() {
1✔
1026
        let mut tx = HTTP2Transaction::new();
1✔
1027
        let head = parser::HTTP2FrameHeader {
1✔
1028
            length: 0,
1✔
1029
            ftype: parser::HTTP2FrameType::Headers as u8,
1✔
1030
            flags: 0,
1✔
1031
            reserved: 0,
1✔
1032
            stream_id: 1,
1✔
1033
        };
1✔
1034
        let mut blocks = Vec::new();
1✔
1035
        let b = parser::HTTP2FrameHeaderBlock {
1✔
1036
            name: "Host".as_bytes().to_vec().into(),
1✔
1037
            value: "abc.com".as_bytes().to_vec().into(),
1✔
1038
            error: parser::HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeSuccess,
1✔
1039
            sizeupdate: 0,
1✔
1040
        };
1✔
1041
        blocks.push(b);
1✔
1042
        let b2 = parser::HTTP2FrameHeaderBlock {
1✔
1043
            name: "Host".as_bytes().to_vec().into(),
1✔
1044
            value: "efg.net".as_bytes().to_vec().into(),
1✔
1045
            error: parser::HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeSuccess,
1✔
1046
            sizeupdate: 0,
1✔
1047
        };
1✔
1048
        blocks.push(b2);
1✔
1049
        let hs = parser::HTTP2FrameHeaders {
1✔
1050
            padlength: None,
1✔
1051
            priority: None,
1✔
1052
            blocks,
1✔
1053
        };
1✔
1054
        let txdata = HTTP2FrameTypeData::HEADERS(hs);
1✔
1055
        tx.frames_ts.push(HTTP2Frame {
1✔
1056
            header: head,
1✔
1057
            data: txdata,
1✔
1058
        });
1✔
1059
        match http2_frames_get_header_value(&mut tx, Direction::ToServer, "Host") {
1✔
1060
            Ok(x) => {
1✔
1061
                assert_eq!(x, "abc.com, efg.net".as_bytes());
1✔
1062
            }
1063
            Err(e) => {
1064
                panic!("Result should not have been an error: {:?}", e);
1065
            }
1066
        }
1067
    }
1✔
1068
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc