TelegramBots / Telegram.Bot

.NET Client for Telegram Bot API
https://telegrambots.github.io/book
MIT License
3.08k stars 680 forks source link

Calling MakeRequestAsync with Stream content more then once results in error #1336

Open karb0f0s opened 5 months ago

karb0f0s commented 5 months ago

Calling MakeRequestAsync with Stream content more then once results in error.

MakeRequestAsync generates an HttpContent content each time it's called:

https://github.com/TelegramBots/Telegram.Bot/blob/843756aeb5cc8d8b94e30835d8c55ee5e98f2a7b/src/Telegram.Bot/TelegramBotClient.cs#L96

Some reqests contain InputFileStream content that forms a multi-part HttpContent with ToMultipartFormDataContent. Unerneath it StreamContent adds to the MultipartFormDataContent which rewinds Stream and next call tries to add content from the end of the Stream, resulting in empty content.

https://github.com/TelegramBots/Telegram.Bot/blob/843756aeb5cc8d8b94e30835d8c55ee5e98f2a7b/src/Telegram.Bot/Extensions/HttpContentExtensions.cs#L24-L31

tuscen commented 5 months ago

@karb0f0s Can you make a repro project so I can look into it, please?

karb0f0s commented 5 months ago

@tuscen https://github.com/karb0f0s/BotClientContentCacheTest

you might need to initialize a submodule first: git submodule init && git submodule update