Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/event_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ impl EventSource {
Self::new(reqwest::Client::new().get(url)).unwrap()
}

/// Create a simple EventSource based on a POST request
pub fn post<T: IntoUrl>(url: T, content_type: &str, input: reqwest::Body) -> Self {
Self::new(
reqwest::Client::new()
.post(url)
.body(input)
.header(reqwest::header::CONTENT_TYPE, content_type),
)
.unwrap()
}

/// Create a simple EventSource based on a PUT request
pub fn put<T: IntoUrl>(url: T, content_type: &str, input: reqwest::Body) -> Self {
Self::new(
reqwest::Client::new()
.put(url)
.body(input)
.header(reqwest::header::CONTENT_TYPE, content_type),
)
.unwrap()
}

/// Close the EventSource stream and stop trying to reconnect
pub fn close(&mut self) {
self.is_closed = true;
Expand Down