“Content-Length” Header in Django Framework for IoT Application

I am currently utilizing the “Django framework” to develop a server for an “Internet of Things (IoT)” application. The server receives “POST requests” from a client, which is a Microcontroller.

The issue lies in the “Content-Length” header within the response sent by the server. Despite explicitly setting this header attribute in the views, it appears that Django drops it when sending the response.

This omission is evident from the “controller’s log files”, which indicate that the response lacks the “Content-Length” attribute. Consequently, the controller (the client) fails to process the response correctly.

As someone who has grown fond of Django, I am keen on resolving this issue. However, if a solution cannot be found, I may be compelled to explore alternative frameworks.

Could you kindly provide guidance on how to address this issue effectively?

Thank you for your assistance.

Only for streaming responses - which is a situation in which it doesn’t make sense.

In all other cases, the process_response method in the CommonMiddleware class will add a Content-Length header to the response if one is not present.

Now, having said that, when you POST data using the typical Django processing flow, the first response to the POST is usually a redirect - and that is returned with a Content-Length 0.

I’d say it’s more likely that the controller isn’t handling the 302 response correctly.

The issue was solved, I used postman to test what Django was returning, it was returning a content-length attribute even if I didn’t provide it explicitly. The issue was in the controller and it was solved after updating the firmware of the controller, Thank you for your help.