folk-plugin-http 0.1.1

HTTP plugin for Folk — accepts connections via hyper and dispatches to PHP workers
Documentation
use bytes::Bytes;
use folk_plugin_http::payload::{HttpResponsePayload, decode_response};

#[tokio::test]
async fn response_payload_roundtrip() {
    let payload = HttpResponsePayload {
        status: 200,
        headers: [("content-type".into(), "text/plain".into())].into(),
        body: Bytes::from("hello"),
    };
    let encoded = Bytes::from(rmp_serde::to_vec_named(&payload).unwrap());
    let response = decode_response(encoded).unwrap();
    assert_eq!(response.status(), 200);
    assert_eq!(
        response.headers().get("content-type").unwrap(),
        "text/plain"
    );
}

#[tokio::test]
async fn request_payload_roundtrip() {
    use folk_plugin_http::payload::{HttpRequestPayload, encode_request};

    let req = hyper::Request::builder()
        .method("POST")
        .uri("/test?foo=bar")
        .header("content-type", "application/json")
        .body(http_body_util::Full::new(Bytes::from(r#"{"key":"value"}"#)))
        .unwrap();

    let encoded = encode_request(req).await.unwrap();
    let decoded: HttpRequestPayload = rmp_serde::from_slice(&encoded).unwrap();

    assert_eq!(decoded.method, "POST");
    assert_eq!(decoded.uri, "/test?foo=bar");
    assert_eq!(
        decoded.headers.get("content-type").unwrap(),
        "application/json"
    );
    assert_eq!(decoded.body, Bytes::from(r#"{"key":"value"}"#));
}

#[tokio::test]
#[ignore = "requires php + msgpack"]
async fn http_plugin_serves_real_request() {
    // Boot a FolkServer with HttpPlugin + real PipeRuntime
    // pointing at a minimal PHP script that returns HTTP 200.
    // Make a GET request with reqwest.
    // Assert status 200.
    todo!("requires full Folk server with PHP workers")
}