lobehub / lobe-chat

🤯 Lobe Chat - an open-source, modern-design LLMs/AI chat framework. Supports Multi AI Providers( OpenAI / Claude 3 / Gemini / Ollama / Bedrock / Azure / Mistral / Perplexity ), Multi-Modals (Vision/TTS) and plugin system. One-click FREE deployment of your private ChatGPT chat application.
https://chat-preview.lobehub.com
Other
35.49k stars 8.37k forks source link

[Bug] Plugin requests not set content-type header as json #2216

Open ifsheldon opened 2 months ago

ifsheldon commented 2 months ago

💻 Operating System

macOS

📦 Environment

Vercel / Zeabur / Sealos

🌐 Browser

Safari

🐛 Bug Description

Hi! I'm developing a custom plugin. I turned on a middleware which checks if a post request has set content-type header as application/json, but then I found the post requests with arguments in JSON from the plugin failed because the http requests set content-type as text/plain. So I wonder if this behaviour is intended or is a minor bug.

🚦 Expected Behavior

I don't know if this behaviour is intended or is a minor bug. If it's a bug, we should set post requests with JSON payload and correct content-type header.

📷 Recurrence Steps

You can set up a mock plugin and check if the post requests received have set correct content-type header.

📝 Additional Information

No response

lobehubbot commented 2 months ago

👀 @ifsheldon

Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible. Please make sure you have given us as much context as possible.\ 非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。

arvinxx commented 2 months ago

I think it might be a mistake.

ifsheldon commented 2 months ago

@arvinxx Do you know where to fix it? I can try to make a PR

arvinxx commented 2 months ago

@ifsheldon do you mean the gateway send plugin request?

arvinxx commented 2 months ago

if you mean the gateway, the caller is here: https://github.com/lobehub/chat-plugins-gateway/blob/main/src/gateway.ts#L243-L258

and the plugin setting code : https://github.com/lobehub/chat-plugin-sdk/blob/master/src/request.ts#L27-L33

ifsheldon commented 2 months ago

I saw the plugin setting code before, but it's a bit twisted for me. I don't know where the settings come from.

A monkey patch would be to just add a header into settings. but I think probably it's best to go way back to OpenAPI parsing and see what content type the OpenAPI configs require.

What do you think? @arvinxx