Skip to content

Commit 73bff4e

Browse files
authoredAug 4, 2021
feat(client): expose http09 and http1 options on client::conn::Builder (#2611)
These options are currently available on the high-level builder only. Along the way, rename the setters to follow the public API conventions and add docs. Closes #2461
1 parent 91bbce4 commit 73bff4e

File tree

3 files changed

+62
-13
lines changed

3 files changed

+62
-13
lines changed
 

‎src/client/client.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ impl Builder {
971971
///
972972
/// Default is an adaptive read buffer.
973973
pub fn http1_read_buf_exact_size(&mut self, sz: usize) -> &mut Self {
974-
self.conn_builder.h1_read_buf_exact_size(Some(sz));
974+
self.conn_builder.http1_read_buf_exact_size(Some(sz));
975975
self
976976
}
977977

@@ -987,7 +987,7 @@ impl Builder {
987987
#[cfg(feature = "http1")]
988988
#[cfg_attr(docsrs, doc(cfg(feature = "http1")))]
989989
pub fn http1_max_buf_size(&mut self, max: usize) -> &mut Self {
990-
self.conn_builder.h1_max_buf_size(max);
990+
self.conn_builder.http1_max_buf_size(max);
991991
self
992992
}
993993

@@ -1012,7 +1012,7 @@ impl Builder {
10121012
/// [RFC 7230 Section 3.2.4.]: https://tools.ietf.org/html/rfc7230#section-3.2.4
10131013
pub fn http1_allow_spaces_after_header_name_in_responses(&mut self, val: bool) -> &mut Self {
10141014
self.conn_builder
1015-
.h1_allow_spaces_after_header_name_in_responses(val);
1015+
.http1_allow_spaces_after_header_name_in_responses(val);
10161016
self
10171017
}
10181018

@@ -1023,7 +1023,7 @@ impl Builder {
10231023
///
10241024
/// Default is false.
10251025
pub fn http1_title_case_headers(&mut self, val: bool) -> &mut Self {
1026-
self.conn_builder.h1_title_case_headers(val);
1026+
self.conn_builder.http1_title_case_headers(val);
10271027
self
10281028
}
10291029

@@ -1034,15 +1034,15 @@ impl Builder {
10341034
///
10351035
/// Default is false.
10361036
pub fn http1_preserve_header_case(&mut self, val: bool) -> &mut Self {
1037-
self.conn_builder.h1_preserve_header_case(val);
1037+
self.conn_builder.http1_preserve_header_case(val);
10381038
self
10391039
}
10401040

10411041
/// Set whether HTTP/0.9 responses should be tolerated.
10421042
///
10431043
/// Default is false.
10441044
pub fn http09_responses(&mut self, val: bool) -> &mut Self {
1045-
self.conn_builder.h09_responses(val);
1045+
self.conn_builder.http09_responses(val);
10461046
self
10471047
}
10481048

‎src/client/conn.rs

+55-6
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,34 @@ impl Builder {
550550
self
551551
}
552552

553-
pub(super) fn h09_responses(&mut self, enabled: bool) -> &mut Builder {
553+
/// Set whether HTTP/0.9 responses should be tolerated.
554+
///
555+
/// Default is false.
556+
pub fn http09_responses(&mut self, enabled: bool) -> &mut Builder {
554557
self.h09_responses = enabled;
555558
self
556559
}
557560

558-
pub(crate) fn h1_allow_spaces_after_header_name_in_responses(
561+
/// Set whether HTTP/1 connections will accept spaces between header names
562+
/// and the colon that follow them in responses.
563+
///
564+
/// You probably don't need this, here is what [RFC 7230 Section 3.2.4.] has
565+
/// to say about it:
566+
///
567+
/// > No whitespace is allowed between the header field-name and colon. In
568+
/// > the past, differences in the handling of such whitespace have led to
569+
/// > security vulnerabilities in request routing and response handling. A
570+
/// > server MUST reject any received request message that contains
571+
/// > whitespace between a header field-name and colon with a response code
572+
/// > of 400 (Bad Request). A proxy MUST remove any such whitespace from a
573+
/// > response message before forwarding the message downstream.
574+
///
575+
/// Note that this setting does not affect HTTP/2.
576+
///
577+
/// Default is false.
578+
///
579+
/// [RFC 7230 Section 3.2.4.]: https://tools.ietf.org/html/rfc7230#section-3.2.4
580+
pub fn http1_allow_spaces_after_header_name_in_responses(
559581
&mut self,
560582
enabled: bool,
561583
) -> &mut Builder {
@@ -564,24 +586,51 @@ impl Builder {
564586
self
565587
}
566588

567-
pub(super) fn h1_title_case_headers(&mut self, enabled: bool) -> &mut Builder {
589+
/// Set whether HTTP/1 connections will write header names as title case at
590+
/// the socket level.
591+
///
592+
/// Note that this setting does not affect HTTP/2.
593+
///
594+
/// Default is false.
595+
pub fn http1_title_case_headers(&mut self, enabled: bool) -> &mut Builder {
568596
self.h1_title_case_headers = enabled;
569597
self
570598
}
571599

572-
pub(crate) fn h1_preserve_header_case(&mut self, enabled: bool) -> &mut Builder {
600+
/// Set whether HTTP/1 connections will write header names as provided
601+
/// at the socket level.
602+
///
603+
/// Note that this setting does not affect HTTP/2.
604+
///
605+
/// Default is false.
606+
pub fn http1_preserve_header_case(&mut self, enabled: bool) -> &mut Builder {
573607
self.h1_preserve_header_case = enabled;
574608
self
575609
}
576610

577-
pub(super) fn h1_read_buf_exact_size(&mut self, sz: Option<usize>) -> &mut Builder {
611+
/// Sets the exact size of the read buffer to *always* use.
612+
///
613+
/// Note that setting this option unsets the `http1_max_buf_size` option.
614+
///
615+
/// Default is an adaptive read buffer.
616+
pub fn http1_read_buf_exact_size(&mut self, sz: Option<usize>) -> &mut Builder {
578617
self.h1_read_buf_exact_size = sz;
579618
self.h1_max_buf_size = None;
580619
self
581620
}
582621

622+
/// Set the maximum buffer size for the connection.
623+
///
624+
/// Default is ~400kb.
625+
///
626+
/// Note that setting this option unsets the `http1_read_exact_buf_size` option.
627+
///
628+
/// # Panics
629+
///
630+
/// The minimum value allowed is 8192. This method panics if the passed `max` is less than the minimum.
583631
#[cfg(feature = "http1")]
584-
pub(super) fn h1_max_buf_size(&mut self, max: usize) -> &mut Self {
632+
#[cfg_attr(docsrs, doc(cfg(feature = "http1")))]
633+
pub fn http1_max_buf_size(&mut self, max: usize) -> &mut Self {
585634
assert!(
586635
max >= proto::h1::MINIMUM_MAX_BUFFER_SIZE,
587636
"the max_buf_size cannot be smaller than the minimum that h1 specifies."

‎src/ffi/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ ffi_fn! {
107107
/// Creates a new set of HTTP clientconn options to be used in a handshake.
108108
fn hyper_clientconn_options_new() -> *mut hyper_clientconn_options {
109109
let mut builder = conn::Builder::new();
110-
builder.h1_preserve_header_case(true);
110+
builder.http1_preserve_header_case(true);
111111

112112
Box::into_raw(Box::new(hyper_clientconn_options {
113113
builder,

0 commit comments

Comments
 (0)
Please sign in to comment.