martindisch / coap-lite

A lightweight CoAP message manipulation crate, ideal for embedded environments
Other
23 stars 17 forks source link

Copying request payload to the reply #37

Closed amvasil-v closed 4 months ago

amvasil-v commented 4 months ago

``While testing coap-rs, which is based on coap-lite, I noticed that coap server by default replies to the POST and PUT requests with an echo of the request, which is confusing. Moreover, it copies request payload to the reply messages to a block1 request, which is clearly a bug.

This happens because in src/response.rs in the function pub fn new(request: &Packet): packet.payload = request.payload.clone(); request payload is always copied to the reply.

Is there a particular reason to do it, or can this line be deleted? I think in all use cases user is actually responsible for populating response.message.payload.

martindisch commented 4 months ago

I'm not sure, this behavior has been here from the beginning in #1. @Covertness do you remember the reasoning by chance, or have a preference on the matter?

Covertness commented 4 months ago

I think it was used to build the response quickly. Of cource it can be deleted.

amvasil-v commented 4 months ago

@martindisch @Covertness Thanks for a quick reply! Created PR #38.

martindisch commented 4 months ago

Released in 0.12.0.