Skip to content

Commit 89048f4

Browse files
authored
refactor(ffi): remove the "raw" headers option in C API (#3002)
Closes #2995
1 parent bd7928f commit 89048f4

File tree

9 files changed

+2
-141
lines changed

9 files changed

+2
-141
lines changed

capi/examples/upload.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,6 @@ static void print_informational(void *userdata, hyper_response *resp) {
153153
uint16_t http_status = hyper_response_status(resp);
154154

155155
printf("\nInformational (1xx): %d\n", http_status);
156-
157-
const hyper_buf *headers = hyper_response_headers_raw(resp);
158-
if (headers) {
159-
write(1, hyper_buf_bytes(headers), hyper_buf_len(headers));
160-
}
161156
}
162157

163158
typedef enum {
@@ -228,7 +223,6 @@ int main(int argc, char *argv[]) {
228223
// Prepare client options
229224
hyper_clientconn_options *opts = hyper_clientconn_options_new();
230225
hyper_clientconn_options_exec(opts, exec);
231-
hyper_clientconn_options_headers_raw(opts, 1);
232226

233227
hyper_task *handshake = hyper_clientconn_handshake(io, opts);
234228
hyper_task_set_userdata(handshake, (void *)EXAMPLE_HANDSHAKE);

capi/include/hyper.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,6 @@ void hyper_clientconn_options_exec(struct hyper_clientconn_options *opts,
391391
*/
392392
enum hyper_code hyper_clientconn_options_http2(struct hyper_clientconn_options *opts, int enabled);
393393

394-
/*
395-
Set the whether to include a copy of the raw headers in responses
396-
received on this connection.
397-
398-
Pass `0` to disable, `1` to enable.
399-
400-
If enabled, see `hyper_response_headers_raw()` for usage.
401-
*/
402-
enum hyper_code hyper_clientconn_options_headers_raw(struct hyper_clientconn_options *opts,
403-
int enabled);
404-
405394
/*
406395
Set whether HTTP/1 connections will accept obsolete line folding for header values.
407396
Newline codepoints (\r and \n) will be transformed to spaces when parsing.
@@ -567,21 +556,6 @@ const uint8_t *hyper_response_reason_phrase(const struct hyper_response *resp);
567556
*/
568557
size_t hyper_response_reason_phrase_len(const struct hyper_response *resp);
569558

570-
/*
571-
Get a reference to the full raw headers of this response.
572-
573-
You must have enabled `hyper_clientconn_options_headers_raw()`, or this
574-
will return NULL.
575-
576-
The returned `hyper_buf *` is just a reference, owned by the response.
577-
You need to make a copy if you wish to use it after freeing the
578-
response.
579-
580-
The buffer is not null-terminated, see the `hyper_buf` functions for
581-
getting the bytes and length.
582-
*/
583-
const struct hyper_buf *hyper_response_headers_raw(const struct hyper_response *resp);
584-
585559
/*
586560
Get the HTTP version used by this response.
587561

src/client/conn/http1.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ pub struct Builder {
108108
h1_title_case_headers: bool,
109109
h1_preserve_header_case: bool,
110110
#[cfg(feature = "ffi")]
111-
h1_headers_raw: bool,
112-
#[cfg(feature = "ffi")]
113111
h1_preserve_header_order: bool,
114112
h1_read_buf_exact_size: Option<usize>,
115113
h1_max_buf_size: Option<usize>,
@@ -300,8 +298,6 @@ impl Builder {
300298
h1_title_case_headers: false,
301299
h1_preserve_header_case: false,
302300
#[cfg(feature = "ffi")]
303-
h1_headers_raw: false,
304-
#[cfg(feature = "ffi")]
305301
h1_preserve_header_order: false,
306302
h1_max_buf_size: None,
307303
}
@@ -456,12 +452,6 @@ impl Builder {
456452
self
457453
}
458454

459-
#[cfg(feature = "ffi")]
460-
pub(crate) fn http1_headers_raw(&mut self, enabled: bool) -> &mut Builder {
461-
self.h1_headers_raw = enabled;
462-
self
463-
}
464-
465455
/// Sets the exact size of the read buffer to *always* use.
466456
///
467457
/// Note that setting this option unsets the `http1_max_buf_size` option.
@@ -535,10 +525,7 @@ impl Builder {
535525
if opts.h1_preserve_header_order {
536526
conn.set_preserve_header_order();
537527
}
538-
#[cfg(feature = "ffi")]
539-
if opts.h1_headers_raw {
540-
conn.set_raw_headers(true);
541-
}
528+
542529
if opts.h09_responses {
543530
conn.set_h09_responses();
544531
}

src/ffi/client.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use super::task::{hyper_executor, hyper_task, hyper_task_return_type, AsTaskType
1414
/// An options builder to configure an HTTP client connection.
1515
pub struct hyper_clientconn_options {
1616
http1_allow_obsolete_multiline_headers_in_responses: bool,
17-
http1_headers_raw: bool,
1817
http1_preserve_header_case: bool,
1918
http1_preserve_header_order: bool,
2019
http2: bool,
@@ -72,7 +71,6 @@ ffi_fn! {
7271
conn::http1::Builder::new()
7372
.executor(options.exec.clone())
7473
.http1_allow_obsolete_multiline_headers_in_responses(options.http1_allow_obsolete_multiline_headers_in_responses)
75-
.http1_headers_raw(options.http1_headers_raw)
7674
.http1_preserve_header_case(options.http1_preserve_header_case)
7775
.http1_preserve_header_order(options.http1_preserve_header_order)
7876
.handshake::<_, crate::Recv>(io)
@@ -131,7 +129,6 @@ ffi_fn! {
131129
fn hyper_clientconn_options_new() -> *mut hyper_clientconn_options {
132130
Box::into_raw(Box::new(hyper_clientconn_options {
133131
http1_allow_obsolete_multiline_headers_in_responses: false,
134-
http1_headers_raw: false,
135132
http1_preserve_header_case: false,
136133
http1_preserve_header_order: false,
137134
http2: false,
@@ -203,20 +200,6 @@ ffi_fn! {
203200
}
204201
}
205202

206-
ffi_fn! {
207-
/// Set the whether to include a copy of the raw headers in responses
208-
/// received on this connection.
209-
///
210-
/// Pass `0` to disable, `1` to enable.
211-
///
212-
/// If enabled, see `hyper_response_headers_raw()` for usage.
213-
fn hyper_clientconn_options_headers_raw(opts: *mut hyper_clientconn_options, enabled: c_int) -> hyper_code {
214-
let opts = non_null! { &mut *opts ?= hyper_code::HYPERE_INVALID_ARG };
215-
opts.http1_headers_raw = enabled != 0;
216-
hyper_code::HYPERE_OK
217-
}
218-
}
219-
220203
ffi_fn! {
221204
/// Set whether HTTP/1 connections will accept obsolete line folding for header values.
222205
/// Newline codepoints (\r and \n) will be transformed to spaces when parsing.

src/ffi/http_types.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use bytes::Bytes;
22
use libc::{c_int, size_t};
33
use std::ffi::c_void;
44

5-
use super::body::{hyper_body, hyper_buf};
5+
use super::body::hyper_body;
66
use super::error::hyper_code;
77
use super::task::{hyper_task_return_type, AsTaskType};
88
use super::{UserDataPointer, HYPER_ITER_CONTINUE};
@@ -25,8 +25,6 @@ pub struct hyper_headers {
2525
orig_order: OriginalHeaderOrder,
2626
}
2727

28-
pub(crate) struct RawHeaders(pub(crate) hyper_buf);
29-
3028
pub(crate) struct OnInformational {
3129
func: hyper_request_on_informational_callback,
3230
data: UserDataPointer,
@@ -278,27 +276,6 @@ ffi_fn! {
278276
}
279277
}
280278

281-
ffi_fn! {
282-
/// Get a reference to the full raw headers of this response.
283-
///
284-
/// You must have enabled `hyper_clientconn_options_headers_raw()`, or this
285-
/// will return NULL.
286-
///
287-
/// The returned `hyper_buf *` is just a reference, owned by the response.
288-
/// You need to make a copy if you wish to use it after freeing the
289-
/// response.
290-
///
291-
/// The buffer is not null-terminated, see the `hyper_buf` functions for
292-
/// getting the bytes and length.
293-
fn hyper_response_headers_raw(resp: *const hyper_response) -> *const hyper_buf {
294-
let resp = non_null!(&*resp ?= std::ptr::null());
295-
match resp.0.extensions().get::<RawHeaders>() {
296-
Some(raw) => &raw.0,
297-
None => std::ptr::null(),
298-
}
299-
} ?= std::ptr::null()
300-
}
301-
302279
ffi_fn! {
303280
/// Get the HTTP version used by this response.
304281
///

src/proto/h1/conn.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ where
6868
h09_responses: false,
6969
#[cfg(feature = "ffi")]
7070
on_informational: None,
71-
#[cfg(feature = "ffi")]
72-
raw_headers: false,
7371
notify_read: false,
7472
reading: Reading::Init,
7573
writing: Writing::Init,
@@ -142,11 +140,6 @@ where
142140
self.state.allow_half_close = true;
143141
}
144142

145-
#[cfg(feature = "ffi")]
146-
pub(crate) fn set_raw_headers(&mut self, enabled: bool) {
147-
self.state.raw_headers = enabled;
148-
}
149-
150143
pub(crate) fn into_inner(self) -> (I, Bytes) {
151144
self.io.into_inner()
152145
}
@@ -219,8 +212,6 @@ where
219212
h09_responses: self.state.h09_responses,
220213
#[cfg(feature = "ffi")]
221214
on_informational: &mut self.state.on_informational,
222-
#[cfg(feature = "ffi")]
223-
raw_headers: self.state.raw_headers,
224215
}
225216
)) {
226217
Ok(msg) => msg,
@@ -828,8 +819,6 @@ struct State {
828819
/// received.
829820
#[cfg(feature = "ffi")]
830821
on_informational: Option<crate::ffi::OnInformational>,
831-
#[cfg(feature = "ffi")]
832-
raw_headers: bool,
833822
/// Set to true when the Dispatcher should poll read operations
834823
/// again. See the `maybe_notify` method for more.
835824
notify_read: bool,

src/proto/h1/io.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ where
197197
h09_responses: parse_ctx.h09_responses,
198198
#[cfg(feature = "ffi")]
199199
on_informational: parse_ctx.on_informational,
200-
#[cfg(feature = "ffi")]
201-
raw_headers: parse_ctx.raw_headers,
202200
},
203201
)? {
204202
Some(msg) => {
@@ -738,8 +736,6 @@ mod tests {
738736
h09_responses: false,
739737
#[cfg(feature = "ffi")]
740738
on_informational: &mut None,
741-
#[cfg(feature = "ffi")]
742-
raw_headers: false,
743739
};
744740
assert!(buffered
745741
.parse::<ClientTransaction>(cx, parse_ctx)

src/proto/h1/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ pub(crate) struct ParseContext<'a> {
9292
h09_responses: bool,
9393
#[cfg(feature = "ffi")]
9494
on_informational: &'a mut Option<crate::ffi::OnInformational>,
95-
#[cfg(feature = "ffi")]
96-
raw_headers: bool,
9795
}
9896

9997
/// Passed to Http1Transaction::encode

0 commit comments

Comments
 (0)