forked from chris-morgan/rust-http
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::rt::io::net::tcp::TcpStream; | ||
use std::rt::io::net::ip::{SocketAddr, Ipv4Addr}; | ||
|
||
use method; | ||
use client::request::RequestWriter; | ||
use client::response::ResponseReader; | ||
|
||
// TODO: Implement a Response trait | ||
|
||
pub fn request(method: method::Method, url: ~str) | ||
-> Result<ResponseReader<TcpStream>, ~RequestWriter<TcpStream>>{ | ||
|
||
let url = FromStr::from_str(url).expect("Uh oh, that's *really* badly broken!"); | ||
let mut request = ~RequestWriter::new(method, url); | ||
|
||
// TODO: https://github.com/chris-morgan/rust-http/issues/10 | ||
// Temporary measure, as hostname lookup is not yet supported in std::rt::io. | ||
request.remote_addr = Some(SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 8001 }); | ||
request.read_response() | ||
} | ||
|
||
pub fn get(url: ~str) | ||
-> Result<ResponseReader<TcpStream>, ~RequestWriter<TcpStream>> { | ||
|
||
request(method::Get, url) | ||
} | ||
|
||
// TODO: Add body | ||
pub fn post(url: ~str) | ||
-> Result<ResponseReader<TcpStream>, ~RequestWriter<TcpStream>> { | ||
|
||
request(method::Post, url) | ||
} | ||
|
||
// TODO: Add body | ||
pub fn patch(url: ~str) | ||
-> Result<ResponseReader<TcpStream>, ~RequestWriter<TcpStream>> { | ||
|
||
request(method::Patch, url) | ||
} | ||
|
||
// TODO: Add body | ||
pub fn put(url: ~str) | ||
-> Result<ResponseReader<TcpStream>, ~RequestWriter<TcpStream>> { | ||
|
||
request(method::Put, url) | ||
} | ||
|
||
pub fn delete(url: ~str) | ||
-> Result<ResponseReader<TcpStream>, ~RequestWriter<TcpStream>> { | ||
|
||
request(method::Delete, url) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub use self::request::RequestWriter; | ||
pub use self::response::ResponseReader; | ||
|
||
pub mod api; | ||
pub mod request; | ||
pub mod response; |