From 34ccde056ab010274cf7419c5c44e5345fc4048e Mon Sep 17 00:00:00 2001 From: Sean Billig Date: Fri, 29 Mar 2013 22:40:49 -0500 Subject: [PATCH 1/7] Update .gitignore --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f264288..6816cb1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ http_client *~ *.so -*.dylib \ No newline at end of file +*.dylib +*.a +*.dummy +*.o +Makefile From f34481d09cf7a0bc93783fe51a5bb54b032ecb26 Mon Sep 17 00:00:00 2001 From: Sean Billig Date: Fri, 29 Mar 2013 22:41:27 -0500 Subject: [PATCH 2/7] rustpkg support --- pkg.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 pkg.rs diff --git a/pkg.rs b/pkg.rs new file mode 100644 index 0000000..5d95a73 --- /dev/null +++ b/pkg.rs @@ -0,0 +1,10 @@ +#[pkg(id = "http-client", + vers = "0.1.0")]; + +use core::run; + +#[pkg_do(build)] +fn main() { + run::run_program("./configure", []); + run::run_program("make", []); +} From aaa1395baa5e53d89fabb6ef8521078a8cc37938 Mon Sep 17 00:00:00 2001 From: Sean Billig Date: Sat, 30 Mar 2013 10:23:45 -0500 Subject: [PATCH 3/7] Replace fail_unless with assert --- http_client.rc | 6 +++--- parser.rs | 2 +- request.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/http_client.rc b/http_client.rc index 69a5e07..b93ed81 100644 --- a/http_client.rc +++ b/http_client.rc @@ -282,7 +282,7 @@ pub fn test_resolve_error() { let request = uv_http_request(url); let events = sequence(request); - fail_unless!(events == ~[ + assert!(events == ~[ Error(ErrorDnsResolution), ]); } @@ -296,7 +296,7 @@ pub fn test_connect_error() { let request = uv_http_request(url); let events = sequence(request); - fail_unless!(events == ~[ + assert!(events == ~[ Error(ErrorConnect), ]); } @@ -337,7 +337,7 @@ pub fn test_simple_body() { } } - fail_unless!(found); + assert!(found); } #[test] diff --git a/parser.rs b/parser.rs index 2470969..d3fe02e 100644 --- a/parser.rs +++ b/parser.rs @@ -81,7 +81,7 @@ pub impl Parser { fn callbacks(http_parser: *http_parser::http_parser) -> *ParserCallbacks { unsafe { - fail_unless!((*http_parser).data.is_not_null()); + assert!((*http_parser).data.is_not_null()); return (*http_parser).data as *ParserCallbacks; } } diff --git a/request.rs b/request.rs index 2ee6ab0..8970c9c 100644 --- a/request.rs +++ b/request.rs @@ -24,7 +24,7 @@ pub fn build_request(url: Url) -> ~str { #[allow(non_implicitly_copyable_typarams)] fn should_request_slash_when_path_is_empty() { let url = url::from_str(~"http://host").get(); - fail_unless!(url.path.is_empty()); + assert!(url.path.is_empty()); let headers = build_request(url); - fail_unless!(headers.contains(~"GET / ")); + assert!(headers.contains(~"GET / ")); } From c362f6119d6dfb1523a551e1047defcf5741eabc Mon Sep 17 00:00:00 2001 From: Sean Billig Date: Sat, 30 Mar 2013 15:46:43 -0500 Subject: [PATCH 4/7] Update tests for language changes --- http_client.rc | 32 ++++++++++++++++---------------- request.rs | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/http_client.rc b/http_client.rc index b93ed81..e6ac26a 100644 --- a/http_client.rc +++ b/http_client.rc @@ -20,7 +20,7 @@ use std::net::ip::{ IpAddr, IpGetAddrErr, Ipv4, Ipv6 }; use std::net::tcp::{connect, TcpErrData, TcpSocket}; -use std::net::url::Url; +use std::net::url; use std::uv_global_loop; use connection::{ Connection, ConnectionFactory, UvConnectionFactory, @@ -53,7 +53,7 @@ pub enum RequestError { ErrorMisc } -/// Request +/// Request #[deriving(Eq)] pub enum RequestEvent { Status(StatusCode), @@ -71,7 +71,7 @@ pub fn uv_dns_resolver() -> DnsResolver { return r; } -pub fn uv_http_request(url: Url) -> HttpRequest { +pub fn uv_http_request(url: url::Url) -> HttpRequest { HttpRequest(uv_dns_resolver(), UvConnectionFactory, url) } @@ -79,14 +79,14 @@ pub fn uv_http_request(url: Url) -> HttpRequest pub struct HttpRequest { resolve_ip_addr: DnsResolver, connection_factory: CF, - url: Url, + url: url::Url, parser: Parser, cb: @fn(+ev: RequestEvent) } pub fn HttpRequest>(resolver: DnsResolver, connection_factory: CF, - url: Url) -> + url: url::Url) -> HttpRequest { HttpRequest { resolve_ip_addr: resolver, @@ -265,9 +265,9 @@ pub impl> HttpRequest { } #[allow(non_implicitly_copyable_typarams)] -pub fn sequence>(request: &mut HttpRequest) -> +pub fn sequence>(request: &mut HttpRequest) -> ~[RequestEvent] { - + let events = @mut ~[]; do request.begin |event| { vec::push(&mut *events, event) @@ -279,8 +279,8 @@ pub fn sequence>(request: &mut HttpReque #[allow(non_implicitly_copyable_typarams)] pub fn test_resolve_error() { let url = url::from_str(~"http://example.com_not_real/").get(); - let request = uv_http_request(url); - let events = sequence(request); + let mut request = uv_http_request(url); + let events = sequence(&mut request); assert!(events == ~[ Error(ErrorDnsResolution), @@ -293,8 +293,8 @@ pub fn test_connect_error() { // This address is invalid because the first octet // of a class A address cannot be 0 let url = url::from_str(~"http://0.42.42.42/").get(); - let request = uv_http_request(url); - let events = sequence(request); + let mut request = uv_http_request(url); + let events = sequence(&mut request); assert!(events == ~[ Error(ErrorConnect), @@ -305,8 +305,8 @@ pub fn test_connect_error() { #[allow(non_implicitly_copyable_typarams)] pub fn test_connect_success() { let url = url::from_str(~"http://example.com/").get(); - let request = uv_http_request(url); - let events = sequence(request); + let mut request = uv_http_request(url); + let events = sequence(&mut request); for events.each |ev| { match *ev { @@ -321,15 +321,15 @@ pub fn test_connect_success() { #[allow(non_implicitly_copyable_typarams)] pub fn test_simple_body() { let url = url::from_str(~"http://www.iana.org/").get(); - let request = uv_http_request(url); - let events = sequence(request); + let mut request = uv_http_request(url); + let events = sequence(&mut request); let mut found = false; for events.each |ev| { match ev { &Payload(ref value) => { - if str::from_bytes((copy value).get()).to_lower().contains(~"doctype html") { + if str::from_bytes((copy value).take()).to_lower().contains(~"doctype html") { found = true } } diff --git a/request.rs b/request.rs index 8970c9c..d2ba82f 100644 --- a/request.rs +++ b/request.rs @@ -1,6 +1,6 @@ -use std::net::url::Url; +use std::net::url; -pub fn build_request(url: Url) -> ~str { +pub fn build_request(url: url::Url) -> ~str { let host = copy url.host; let mut path = if url.path.len() > 0 { copy url.path } else { ~"/" }; From 77c2f82bca7b7b33c87c43cef18d72dd966bfcba Mon Sep 17 00:00:00 2001 From: Sean Billig Date: Sat, 30 Mar 2013 16:03:40 -0500 Subject: [PATCH 5/7] Change pkg id to http_client --- pkg.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg.rs b/pkg.rs index 5d95a73..5400e37 100644 --- a/pkg.rs +++ b/pkg.rs @@ -1,4 +1,4 @@ -#[pkg(id = "http-client", +#[pkg(id = "http_client", vers = "0.1.0")]; use core::run; From 29cd8e0e0772a71474a70ae1e1541e2fd63bd9ec Mon Sep 17 00:00:00 2001 From: Sean Billig Date: Sun, 31 Mar 2013 13:56:00 -0500 Subject: [PATCH 6/7] Add rustpkg commands to build crate --- pkg.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg.rs b/pkg.rs index 5400e37..4c1fc00 100644 --- a/pkg.rs +++ b/pkg.rs @@ -1,10 +1,13 @@ #[pkg(id = "http_client", vers = "0.1.0")]; +extern mod rustpkg; use core::run; #[pkg_do(build)] fn main() { run::run_program("./configure", []); run::run_program("make", []); + let crate = rustpkg::Crate(~"http_client.rc"); + rustpkg::build(~[crate]); } From 17c91bebe6ba857589177efbcd82269e4e27ad92 Mon Sep 17 00:00:00 2001 From: Sean Billig Date: Sun, 31 Mar 2013 14:04:02 -0500 Subject: [PATCH 7/7] Link in libhttp_parser.a --- http_parser.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/http_parser.rs b/http_parser.rs index 1115773..9242b48 100644 --- a/http_parser.rs +++ b/http_parser.rs @@ -457,8 +457,8 @@ struct struct_unnamed1 { len: uint16_t, } -#[nolink] -#[link_args = "-L. -lhttp_parser"] +#[link_name = "http_parser"] +#[link_args = "-L."] pub extern mod bindgen { fn http_parser_init(++parser: *http_parser, ++_type: enum_http_parser_type);