Skip to content

Commit 8a503a2

Browse files
committed
update micro_http documentation
Signed-off-by: George Pisaltu <gpl@amazon.com>
1 parent 5fe6b78 commit 8a503a2

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

micro_http/src/connection.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ impl<T: Read + Write> HttpConnection<T> {
7171
/// Tries to read new bytes from the stream and automatically update the request.
7272
/// Meant to be used only with non-blocking streams and an `EPOLL` structure.
7373
/// Should be called whenever an `EPOLLIN` event is signaled.
74+
///
75+
/// # Errors
76+
/// `StreamError` is returned when an IO operation fails.
77+
/// `ConnectionClosed` is returned when a client prematurely closes the connection.
78+
/// `ParseError` is returned when a parsing operation fails.
7479
pub fn try_read(&mut self) -> Result<(), ConnectionError> {
7580
// Read some bytes from the stream, which will be appended to what is already
7681
// present in the buffer from a previous call of `try_read`. There are already
@@ -293,6 +298,12 @@ impl<T: Read + Write> HttpConnection<T> {
293298
/// Tries to write the first available response to the provided stream.
294299
/// Meant to be used only with non-blocking streams and an `EPOLL` structure.
295300
/// Should be called whenever an `EPOLLOUT` event is signaled.
301+
///
302+
/// # Errors
303+
/// `StreamError` is returned when an IO operation fails.
304+
/// `ConnectionClosed` is returned when trying to write on a closed connection.
305+
/// `InvalidWrite` is returned when trying to write on a connection with an
306+
/// empty outgoing buffer.
296307
pub fn try_write(&mut self) -> Result<(), ConnectionError> {
297308
if self.response_buffer.is_none() {
298309
if let Some(response) = self.response_queue.pop_front() {
@@ -357,10 +368,16 @@ impl<T: Read + Write> HttpConnection<T> {
357368
self.read_cursor = end_cursor - line_start_index;
358369
}
359370

360-
/// Returns the first parsed request in the queue.
371+
/// Returns the first parsed request in the queue or `None` if the queue
372+
/// is empty.
361373
pub fn pop_parsed_request(&mut self) -> Option<Request> {
362374
self.parsed_requests.pop_front()
363375
}
376+
377+
/// Returns `true` if there are bytes waiting to be written into the stream.
378+
pub fn pending_write(&self) -> bool {
379+
self.response_buffer.is_some() || !self.response_queue.is_empty()
380+
}
364381
}
365382

366383
#[cfg(test)]

micro_http/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@
5656
//! ## Example for creating an HTTP Response
5757
//! ```
5858
//! extern crate micro_http;
59-
//! use micro_http::{Body, Response, StatusCode, Version};
59+
//! use micro_http::{Body, Response, StatusCode, Version, MediaType};
6060
//!
6161
//! let mut response = Response::new(Version::Http10, StatusCode::OK);
6262
//! let body = String::from("This is a test");
6363
//! response.set_body(Body::new(body.clone()));
64+
//! response.set_content_type(MediaType::PlainText);
6465
//!
6566
//! assert!(response.status() == StatusCode::OK);
6667
//! assert_eq!(response.body().unwrap(), Body::new(body));

micro_http/src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct ServerRequest {
3232
}
3333

3434
impl ServerRequest {
35-
/// Creates a new `RequestWithID` object from an existing `Request`,
35+
/// Creates a new `ServerRequest` object from an existing `Request`,
3636
/// adding an identification token.
3737
pub fn new(request: Request, id: u64) -> Self {
3838
ServerRequest { request, id }

0 commit comments

Comments
 (0)