fasttime icon indicating copy to clipboard operation
fasttime copied to clipboard

Reading request bodies always fails

Open kailan opened this issue 4 years ago • 2 comments

#[fastly::main]
pub fn main(req: Request) -> Result<Response, Error> {
    let mut beresp = req.send(API_BACKEND)?;

    let body = beresp.take_body_str();

    beresp.set_body(body);

    Ok(beresp)
}

Any Rust binaries that attempt to read the request body seem to encounter the following error:

thread 'tokio-runtime-worker' panicked at 'slice index starts at 18446744071562068155 but ends at 2148794368', src/memory.rs:71:24

Calling set_body also results in the same error.

kailan avatar Feb 21 '21 21:02 kailan

Thanks for reporting

The closet test I have for that is https://github.com/softprops/fasttime/blob/6ccedfd2ee06dbb78d08b9ad989cd982747fe8b8/tests/app/src/main.rs#L119 but it just sends the response back directly from the backend without reading locally.

I'll take a look at this

softprops avatar Feb 21 '21 23:02 softprops

If I don't get to this sooner I'd also be open to a pull.

I thing the relative code would be here.

https://github.com/softprops/fasttime/blob/6ccedfd2ee06dbb78d08b9ad989cd982747fe8b8/src/fastly_http_body.rs#L119

My testing strategy is to update or add a request handler that covers a respective set of fastly wasm apis, build the test app to produce the wasm file, and then in unit test load that wasm file an run it through the handler interface.

Your example above should at the least give me a new test case to add to my test app

softprops avatar Feb 21 '21 23:02 softprops