// If predictable, computes the length the request will have
// The length should be preditable if only String and file fields have been added,
// but not if a generic reader has been added;
If predictable, computes the length the request will have
The length should be preditable if only String and file fields have been added,
but not if a generic reader has been added.
If predictable computes the length the request will have The length should be preditable if only String and file fields have been added but not if a generic reader has been added .
pub(crate) fn compute_length(&mut self) -> Option<u64> {
        let mut length = 0u64;
        for &(ref name, ref field) in self.fields.iter() {
            match field.value_len() {
                Some(value_length) => {
                    // We are constructing the header just to get its length. To not have to
                    // construct it again when the request is sent we cache these headers.
                    let header = self.percent_encoding.encode_headers(name, field.metadata());
                    let header_length = header.len();
                    self.computed_headers.push(header);
                    // The additions mimick the format string out of which the field is constructed
                    // in Reader. Not the cleanest solution because if that format string is
                    // ever changed then this formula needs to be changed too which is not an
                    // obvious dependency in the code.
                    length += 2
                        + self.boundary().len() as u64
                        + 2
                        + header_length as u64
                        + 4
                        + value_length
                        + 2
                }
                _ => return None,
            }
        }
        // If there is a at least one field there is a special boundary for the very last field.
        if !self.fields.is_empty() {
            length += 2 + self.boundary().len() as u64 + 4
        }
        Some(length)
    }
pub ( crate ) fn compute_length ( & mut self ) -> Option < u64 > { let mut length = 0u64 ; for & ( ref name , ref field ) in self . fields . iter ( ) { match field . value_len ( ) { Some ( value_length ) => { // We are constructing the header just to get its length. To not have to // construct it again when the request is sent we cache these headers. let header = self . percent_encoding . encode_headers ( name , field . metadata ( ) ) ; let header_length = header . len ( ) ; self . computed_headers . push ( header ) ; // The additions mimick the format string out of which the field is constructed // in Reader. Not the cleanest solution because if that format string is // ever changed then this formula needs to be changed too which is not an // obvious dependency in the code. length += 2 + self . boundary ( ) . len ( ) as u64 + 2 + header_length as u64 + 4 + value_length + 2 } _ => return None , } } // If there is a at least one field there is a special boundary for the very last field. if ! self . fields . is_empty ( ) { length += 2 + self . boundary ( ) . len ( ) as u64 + 4 } Some ( length ) }
If predictable, computes the length the request will have
The length should be preditable if only String and file fields have been added,
but not if a generic reader has been added;
If predictable computes the length the request will have The length should be preditable if only String and file fields have been added but not if a generic reader has been added ;
&mut self