Skip to content

Commit

Permalink
refactor(ffi): remove the "raw" headers option in C API (#3002)
Browse files Browse the repository at this point in the history
Closes #2995
  • Loading branch information
dannasman authored Oct 5, 2022
1 parent bd7928f commit 89048f4
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 141 deletions.
6 changes: 0 additions & 6 deletions capi/examples/upload.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@ static void print_informational(void *userdata, hyper_response *resp) {
uint16_t http_status = hyper_response_status(resp);

printf("\nInformational (1xx): %d\n", http_status);

const hyper_buf *headers = hyper_response_headers_raw(resp);
if (headers) {
write(1, hyper_buf_bytes(headers), hyper_buf_len(headers));
}
}

typedef enum {
Expand Down Expand Up @@ -228,7 +223,6 @@ int main(int argc, char *argv[]) {
// Prepare client options
hyper_clientconn_options *opts = hyper_clientconn_options_new();
hyper_clientconn_options_exec(opts, exec);
hyper_clientconn_options_headers_raw(opts, 1);

hyper_task *handshake = hyper_clientconn_handshake(io, opts);
hyper_task_set_userdata(handshake, (void *)EXAMPLE_HANDSHAKE);
Expand Down
26 changes: 0 additions & 26 deletions capi/include/hyper.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,6 @@ void hyper_clientconn_options_exec(struct hyper_clientconn_options *opts,
*/
enum hyper_code hyper_clientconn_options_http2(struct hyper_clientconn_options *opts, int enabled);

/*
Set the whether to include a copy of the raw headers in responses
received on this connection.
Pass `0` to disable, `1` to enable.
If enabled, see `hyper_response_headers_raw()` for usage.
*/
enum hyper_code hyper_clientconn_options_headers_raw(struct hyper_clientconn_options *opts,
int enabled);

/*
Set whether HTTP/1 connections will accept obsolete line folding for header values.
Newline codepoints (\r and \n) will be transformed to spaces when parsing.
Expand Down Expand Up @@ -567,21 +556,6 @@ const uint8_t *hyper_response_reason_phrase(const struct hyper_response *resp);
*/
size_t hyper_response_reason_phrase_len(const struct hyper_response *resp);

/*
Get a reference to the full raw headers of this response.
You must have enabled `hyper_clientconn_options_headers_raw()`, or this
will return NULL.
The returned `hyper_buf *` is just a reference, owned by the response.
You need to make a copy if you wish to use it after freeing the
response.
The buffer is not null-terminated, see the `hyper_buf` functions for
getting the bytes and length.
*/
const struct hyper_buf *hyper_response_headers_raw(const struct hyper_response *resp);

/*
Get the HTTP version used by this response.
Expand Down
15 changes: 1 addition & 14 deletions src/client/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ pub struct Builder {
h1_title_case_headers: bool,
h1_preserve_header_case: bool,
#[cfg(feature = "ffi")]
h1_headers_raw: bool,
#[cfg(feature = "ffi")]
h1_preserve_header_order: bool,
h1_read_buf_exact_size: Option<usize>,
h1_max_buf_size: Option<usize>,
Expand Down Expand Up @@ -300,8 +298,6 @@ impl Builder {
h1_title_case_headers: false,
h1_preserve_header_case: false,
#[cfg(feature = "ffi")]
h1_headers_raw: false,
#[cfg(feature = "ffi")]
h1_preserve_header_order: false,
h1_max_buf_size: None,
}
Expand Down Expand Up @@ -456,12 +452,6 @@ impl Builder {
self
}

#[cfg(feature = "ffi")]
pub(crate) fn http1_headers_raw(&mut self, enabled: bool) -> &mut Builder {
self.h1_headers_raw = enabled;
self
}

/// Sets the exact size of the read buffer to *always* use.
///
/// Note that setting this option unsets the `http1_max_buf_size` option.
Expand Down Expand Up @@ -535,10 +525,7 @@ impl Builder {
if opts.h1_preserve_header_order {
conn.set_preserve_header_order();
}
#[cfg(feature = "ffi")]
if opts.h1_headers_raw {
conn.set_raw_headers(true);
}

if opts.h09_responses {
conn.set_h09_responses();
}
Expand Down
17 changes: 0 additions & 17 deletions src/ffi/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use super::task::{hyper_executor, hyper_task, hyper_task_return_type, AsTaskType
/// An options builder to configure an HTTP client connection.
pub struct hyper_clientconn_options {
http1_allow_obsolete_multiline_headers_in_responses: bool,
http1_headers_raw: bool,
http1_preserve_header_case: bool,
http1_preserve_header_order: bool,
http2: bool,
Expand Down Expand Up @@ -72,7 +71,6 @@ ffi_fn! {
conn::http1::Builder::new()
.executor(options.exec.clone())
.http1_allow_obsolete_multiline_headers_in_responses(options.http1_allow_obsolete_multiline_headers_in_responses)
.http1_headers_raw(options.http1_headers_raw)
.http1_preserve_header_case(options.http1_preserve_header_case)
.http1_preserve_header_order(options.http1_preserve_header_order)
.handshake::<_, crate::Recv>(io)
Expand Down Expand Up @@ -131,7 +129,6 @@ ffi_fn! {
fn hyper_clientconn_options_new() -> *mut hyper_clientconn_options {
Box::into_raw(Box::new(hyper_clientconn_options {
http1_allow_obsolete_multiline_headers_in_responses: false,
http1_headers_raw: false,
http1_preserve_header_case: false,
http1_preserve_header_order: false,
http2: false,
Expand Down Expand Up @@ -203,20 +200,6 @@ ffi_fn! {
}
}

ffi_fn! {
/// Set the whether to include a copy of the raw headers in responses
/// received on this connection.
///
/// Pass `0` to disable, `1` to enable.
///
/// If enabled, see `hyper_response_headers_raw()` for usage.
fn hyper_clientconn_options_headers_raw(opts: *mut hyper_clientconn_options, enabled: c_int) -> hyper_code {
let opts = non_null! { &mut *opts ?= hyper_code::HYPERE_INVALID_ARG };
opts.http1_headers_raw = enabled != 0;
hyper_code::HYPERE_OK
}
}

ffi_fn! {
/// Set whether HTTP/1 connections will accept obsolete line folding for header values.
/// Newline codepoints (\r and \n) will be transformed to spaces when parsing.
Expand Down
25 changes: 1 addition & 24 deletions src/ffi/http_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bytes::Bytes;
use libc::{c_int, size_t};
use std::ffi::c_void;

use super::body::{hyper_body, hyper_buf};
use super::body::hyper_body;
use super::error::hyper_code;
use super::task::{hyper_task_return_type, AsTaskType};
use super::{UserDataPointer, HYPER_ITER_CONTINUE};
Expand All @@ -25,8 +25,6 @@ pub struct hyper_headers {
orig_order: OriginalHeaderOrder,
}

pub(crate) struct RawHeaders(pub(crate) hyper_buf);

pub(crate) struct OnInformational {
func: hyper_request_on_informational_callback,
data: UserDataPointer,
Expand Down Expand Up @@ -278,27 +276,6 @@ ffi_fn! {
}
}

ffi_fn! {
/// Get a reference to the full raw headers of this response.
///
/// You must have enabled `hyper_clientconn_options_headers_raw()`, or this
/// will return NULL.
///
/// The returned `hyper_buf *` is just a reference, owned by the response.
/// You need to make a copy if you wish to use it after freeing the
/// response.
///
/// The buffer is not null-terminated, see the `hyper_buf` functions for
/// getting the bytes and length.
fn hyper_response_headers_raw(resp: *const hyper_response) -> *const hyper_buf {
let resp = non_null!(&*resp ?= std::ptr::null());
match resp.0.extensions().get::<RawHeaders>() {
Some(raw) => &raw.0,
None => std::ptr::null(),
}
} ?= std::ptr::null()
}

ffi_fn! {
/// Get the HTTP version used by this response.
///
Expand Down
11 changes: 0 additions & 11 deletions src/proto/h1/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ where
h09_responses: false,
#[cfg(feature = "ffi")]
on_informational: None,
#[cfg(feature = "ffi")]
raw_headers: false,
notify_read: false,
reading: Reading::Init,
writing: Writing::Init,
Expand Down Expand Up @@ -142,11 +140,6 @@ where
self.state.allow_half_close = true;
}

#[cfg(feature = "ffi")]
pub(crate) fn set_raw_headers(&mut self, enabled: bool) {
self.state.raw_headers = enabled;
}

pub(crate) fn into_inner(self) -> (I, Bytes) {
self.io.into_inner()
}
Expand Down Expand Up @@ -219,8 +212,6 @@ where
h09_responses: self.state.h09_responses,
#[cfg(feature = "ffi")]
on_informational: &mut self.state.on_informational,
#[cfg(feature = "ffi")]
raw_headers: self.state.raw_headers,
}
)) {
Ok(msg) => msg,
Expand Down Expand Up @@ -828,8 +819,6 @@ struct State {
/// received.
#[cfg(feature = "ffi")]
on_informational: Option<crate::ffi::OnInformational>,
#[cfg(feature = "ffi")]
raw_headers: bool,
/// Set to true when the Dispatcher should poll read operations
/// again. See the `maybe_notify` method for more.
notify_read: bool,
Expand Down
4 changes: 0 additions & 4 deletions src/proto/h1/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ where
h09_responses: parse_ctx.h09_responses,
#[cfg(feature = "ffi")]
on_informational: parse_ctx.on_informational,
#[cfg(feature = "ffi")]
raw_headers: parse_ctx.raw_headers,
},
)? {
Some(msg) => {
Expand Down Expand Up @@ -738,8 +736,6 @@ mod tests {
h09_responses: false,
#[cfg(feature = "ffi")]
on_informational: &mut None,
#[cfg(feature = "ffi")]
raw_headers: false,
};
assert!(buffered
.parse::<ClientTransaction>(cx, parse_ctx)
Expand Down
2 changes: 0 additions & 2 deletions src/proto/h1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ pub(crate) struct ParseContext<'a> {
h09_responses: bool,
#[cfg(feature = "ffi")]
on_informational: &'a mut Option<crate::ffi::OnInformational>,
#[cfg(feature = "ffi")]
raw_headers: bool,
}

/// Passed to Http1Transaction::encode
Expand Down
Loading

0 comments on commit 89048f4

Please sign in to comment.