|
1 | 1 | use fastcgi_client::{request::Request, Client, Params}; |
2 | | -use std::env::current_dir; |
3 | | -use tokio::net::TcpStream; |
| 2 | +use std::{env::current_dir, time::Duration}; |
| 3 | +use tokio::{net::TcpStream, time::timeout}; |
4 | 4 |
|
5 | 5 | mod common; |
6 | 6 |
|
@@ -57,3 +57,52 @@ async fn test() { |
57 | 57 | let stderr = dbg!(stderr); |
58 | 58 | assert!(stderr.contains("PHP message: PHP Fatal error: Uncaught Exception: TEST")); |
59 | 59 | } |
| 60 | + |
| 61 | +#[tokio::test] |
| 62 | +async fn post_big_body() { |
| 63 | + common::setup(); |
| 64 | + |
| 65 | + let stream = TcpStream::connect(("127.0.0.1", 9000)).await.unwrap(); |
| 66 | + let mut client = Client::new(stream, true); |
| 67 | + |
| 68 | + let document_root = current_dir().unwrap().join("tests").join("php"); |
| 69 | + let document_root = document_root.to_str().unwrap(); |
| 70 | + let script_name = current_dir() |
| 71 | + .unwrap() |
| 72 | + .join("tests") |
| 73 | + .join("php") |
| 74 | + .join("body-size.php"); |
| 75 | + let script_name = script_name.to_str().unwrap(); |
| 76 | + |
| 77 | + let body = [0u8; 131072]; |
| 78 | + let len = format!("{}", body.len()); |
| 79 | + |
| 80 | + let params = Params::default() |
| 81 | + .set_request_method("POST") |
| 82 | + .set_document_root(document_root) |
| 83 | + .set_script_name("/body-size.php") |
| 84 | + .set_script_filename(script_name) |
| 85 | + .set_request_uri("/body-size.php") |
| 86 | + .set_query_string("") |
| 87 | + .set_document_uri("/body-size.php") |
| 88 | + .set_remote_addr("127.0.0.1") |
| 89 | + .set_remote_port("12345") |
| 90 | + .set_server_addr("127.0.0.1") |
| 91 | + .set_server_port("80") |
| 92 | + .set_server_name("jmjoy-pc") |
| 93 | + .set_content_type("text/plain") |
| 94 | + .set_content_length(&len); |
| 95 | + |
| 96 | + let output = timeout( |
| 97 | + Duration::from_secs(3), |
| 98 | + client.execute(Request::new(params.clone(), &mut &body[..])), |
| 99 | + ) |
| 100 | + .await |
| 101 | + .unwrap() |
| 102 | + .unwrap(); |
| 103 | + |
| 104 | + let stdout = String::from_utf8(output.get_stdout().unwrap_or(Default::default())).unwrap(); |
| 105 | + assert!(stdout.contains("Content-type: text/html; charset=UTF-8")); |
| 106 | + assert!(stdout.contains("\r\n\r\n")); |
| 107 | + assert!(stdout.contains("131072")); |
| 108 | +} |
0 commit comments