Calculating Content-Length with Arbitrary String in Python

My question is how I can calculate the content-length header, especially for strings with unicode characters. Is the len function enough, or do I need sys.getsizeof?
(P.S. this is for CLI Auth but i won’t need to send a repl link because this question is pretty independent of the repl code)

do you mean the (amount of pixels)/(standards letter pixel length)? Cuz there is no really extensive library for this afaik (the reason being is that it’s a lot of hardcoding…)

I mean the content-length header present in an http response. There has to an algorithm, but i just cant find it.

1 Like

I’m pretty sure Content-Length is just the number of bytes in the response. If you’re just sending text, this is typically (utf-8, not utf-16) going to be the number of characters.

sys.getsizeof includes other things that aren’t part of your data, so len should probably be fine. Why do you have to do this manually, though?

2 Likes

ok I don’t know why when I said it doesn’t exist you keep assuming it does? Furthermore, I didn’t really understand what it was and you didn’t really explain sorry I don’t really know but could you explain it

1 Like

Basically it just tells the client how many bytes to read in the response (rather than, for example, null terminating it)

1 Like

To set the content-length of a proxied request after modifying it’s data.

Are you interacting with the sockets directly? Generally if you’re using some sort of web framework (flask, bottle, etc) it handles this for you

im using flask, but im using flask . make_response with a proxy response

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.