Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #12 from brson/master
Browse files Browse the repository at this point in the history
Basic DNS and a parser workaround
  • Loading branch information
brson committed Sep 6, 2013
2 parents 48bc01b + a195a9e commit a72a8e4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
34 changes: 32 additions & 2 deletions src/libhttp/client/request.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use extra::url::Url;
use method::Method;
use std::rt::io::{Reader, Writer};
use std::rt::io::net::ip::SocketAddr;
use std::rt::io::net::get_host_addresses;
use std::rt::io::net::ip::{SocketAddr, Ipv4Addr};
use std::rt::io::net::tcp::TcpStream;
use buffer::BufferedStream;
use headers::request::HeaderCollection;
Expand Down Expand Up @@ -70,10 +71,39 @@ impl<S: Reader + Writer> RequestWriter<S> {
},
};

let remote_addr = url_to_socket_addr(&url);
info!("using ip address %s for %s", remote_addr.to_str(), url.host);

fn url_to_socket_addr(url: &Url) -> SocketAddr {
// Just grab the first IPv4 address
let addrs = get_host_addresses(url.host);
// TODO: Error handling
let addrs = addrs.unwrap();
let addr = do addrs.move_iter().find |&a| {
match a {
Ipv4Addr(*) => true,
_ => false
}
};

// TODO: Error handling
let addr = addr.unwrap();

let port = url.port.clone().unwrap_or_default(~"80");
let port = FromStr::from_str(port);
// TODO: Error handling
let port = port.unwrap();

SocketAddr {
ip: addr,
port: port
}
}

let mut request = RequestWriter {
stream: None,
headers_written: false,
remote_addr: None,
remote_addr: Some(remote_addr),
headers: ~HeaderCollection::new(),
method: method,
url: url,
Expand Down
2 changes: 1 addition & 1 deletion src/libhttp/headers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,6 @@ headers_mod! {
24, "Content-MD5", "Content-Md5", ContentMd5, content_md5, ~str;
25, "Content-Range", "Content-Range", ContentRange, content_range, ~str;
26, "Content-Type", "Content-Type", ContentType, content_type, headers::content_type::MediaType;
27, "Expires", "Expires", Expires, expires, extra::time::Tm;
27, "Expires", "Expires", Expires, expires, ~str; // TODO: Should be Tm
28, "Last-Modified", "Last-Modified", LastModified, last_modified, extra::time::Tm;
}

0 comments on commit a72a8e4

Please sign in to comment.