mirror of
https://github.com/openharmony/third_party_rust_http.git
synced 2026-07-19 14:43:33 -04:00
Panic on reuse of builders
This commit is contained in:
+7
-5
@@ -1,7 +1,6 @@
|
||||
//! HTTP request types.
|
||||
|
||||
use std::any::Any;
|
||||
use std::io;
|
||||
|
||||
use {Uri, Error, Result, HttpTryFrom, Extensions};
|
||||
use header::{HeaderMap, HeaderValue, HeaderMapKey};
|
||||
@@ -511,13 +510,11 @@ impl Builder {
|
||||
|
||||
/// "Consumes" this builder, returning the constructed `Head`.
|
||||
fn head(&mut self) -> Result<Parts> {
|
||||
let ret = self.head.take().expect("cannot reuse request builder");
|
||||
if let Some(e) = self.err.take() {
|
||||
return Err(e)
|
||||
}
|
||||
self.head.take().ok_or_else(|| {
|
||||
io::Error::new(io::ErrorKind::Other, "cannot reuse `Builder`")
|
||||
.into()
|
||||
})
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
/// "Consumes" this builder, using the provided `body` to return a
|
||||
@@ -531,6 +528,11 @@ impl Builder {
|
||||
/// "Bar\r\n")` the error will be returned when this function is called
|
||||
/// rather than when `header` was called.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This method will panic if the builder is reused. The `body` function can
|
||||
/// only be called once.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
|
||||
+7
-5
@@ -1,7 +1,6 @@
|
||||
//! HTTP response types.
|
||||
|
||||
use std::any::Any;
|
||||
use std::io;
|
||||
|
||||
use {Error, Result, HttpTryFrom, Extensions};
|
||||
use header::{HeaderMap, HeaderValue};
|
||||
@@ -453,13 +452,11 @@ impl Builder {
|
||||
|
||||
/// "Consumes" this builder, returning the constructed `Parts`.
|
||||
fn head(&mut self) -> Result<Parts> {
|
||||
let ret = self.head.take().expect("cannot reuse response builder");
|
||||
if let Some(e) = self.err.take() {
|
||||
return Err(e)
|
||||
}
|
||||
self.head.take().ok_or_else(|| {
|
||||
io::Error::new(io::ErrorKind::Other, "cannot reuse `Builder`")
|
||||
.into()
|
||||
})
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
/// "Consumes" this builder, using the provided `body` to return a
|
||||
@@ -473,6 +470,11 @@ impl Builder {
|
||||
/// "Bar\r\n")` the error will be returned when this function is called
|
||||
/// rather than when `header` was called.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This method will panic if the builder is reused. The `body` function can
|
||||
/// only be called once.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
|
||||
Reference in New Issue
Block a user