]> git.proxmox.com Git - rustc.git/blob - src/vendor/curl/tests/post.rs
New upstream version 1.19.0+dfsg1
[rustc.git] / src / vendor / curl / tests / post.rs
1 extern crate curl;
2
3 use std::str;
4 use std::time::Duration;
5
6 macro_rules! t {
7 ($e:expr) => (match $e {
8 Ok(e) => e,
9 Err(e) => panic!("{} failed with {:?}", stringify!($e), e),
10 })
11 }
12
13 use curl::easy::{Easy, Form};
14
15 use server::Server;
16 mod server;
17
18 fn handle() -> Easy {
19 let mut e = Easy::new();
20 t!(e.timeout(Duration::new(20, 0)));
21 return e
22 }
23
24 #[test]
25 fn custom() {
26 let s = Server::new();
27 s.receive("\
28 POST / HTTP/1.1\r\n\
29 Host: 127.0.0.1:$PORT\r\n\
30 Accept: */*\r\n\
31 Content-Length: 142\r\n\
32 Expect: 100-continue\r\n\
33 Content-Type: multipart/form-data; boundary=--[..]\r\n\
34 \r\n\
35 --[..]\r\n\
36 Content-Disposition: form-data; name=\"foo\"\r\n\
37 \r\n\
38 1234\r\n\
39 --[..]\r\n");
40 s.send("HTTP/1.1 200 OK\r\n\r\n");
41
42 let mut handle = handle();
43 let mut form = Form::new();
44 t!(form.part("foo").contents(b"1234").add());
45 t!(handle.url(&s.url("/")));
46 t!(handle.httppost(form));
47 t!(handle.perform());
48 }
49
50 #[test]
51 fn buffer() {
52 let s = Server::new();
53 s.receive("\
54 POST / HTTP/1.1\r\n\
55 Host: 127.0.0.1:$PORT\r\n\
56 Accept: */*\r\n\
57 Content-Length: 181\r\n\
58 Expect: 100-continue\r\n\
59 Content-Type: multipart/form-data; boundary=--[..]\r\n\
60 \r\n\
61 --[..]\r\n\
62 Content-Disposition: form-data; name=\"foo\"; filename=\"bar\"\r\n\
63 Content-Type: foo/bar\r\n\
64 \r\n\
65 1234\r\n\
66 --[..]\r\n");
67 s.send("HTTP/1.1 200 OK\r\n\r\n");
68
69 let mut handle = handle();
70 let mut form = Form::new();
71 t!(form.part("foo")
72 .buffer("bar", b"1234".to_vec())
73 .content_type("foo/bar")
74 .add());
75 t!(handle.url(&s.url("/")));
76 t!(handle.httppost(form));
77 t!(handle.perform());
78 }
79
80 #[test]
81 fn file() {
82 let s = Server::new();
83 s.receive("\
84 POST / HTTP/1.1\r\n\
85 Host: 127.0.0.1:$PORT\r\n\
86 Accept: */*\r\n\
87 Content-Length: 205\r\n\
88 Expect: 100-continue\r\n\
89 Content-Type: multipart/form-data; boundary=--[..]\r\n\
90 \r\n\
91 --[..]\r\n\
92 Content-Disposition: form-data; name=\"foo\"; filename=\"formdata\"\r\n\
93 Content-Type: application/octet-stream\r\n\
94 \r\n\
95 hello\n\
96 \r\n\
97 --[..]\r\n");
98 s.send("HTTP/1.1 200 OK\r\n\r\n");
99
100 let mut handle = handle();
101 let mut form = Form::new();
102 t!(form.part("foo")
103 .file("tests/formdata")
104 .add());
105 t!(handle.url(&s.url("/")));
106 t!(handle.httppost(form));
107 t!(handle.perform());
108 }