-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SDK NODE.JS: Get with body is not http standard #4617
Comments
To address the issue of GET requests returning a 400 Bad Request error due to a body being included, you can modify the Here is how you can modify the async sendRequest(
method,
endpoint,
data = null,
params = null,
stream = false,
headerParams = {}
) {
const headers = {
...{
Authorization: `Bearer ${this.apiKey}`,
"Content-Type": "application/json",
},
...headerParams
};
const url = `${this.baseUrl}${endpoint}`;
let response;
if (stream) {
response = await axios({
method,
url,
data: method === 'GET' ? null : data, // Ensure data is null for GET requests
params,
headers,
responseType: "stream",
});
} else {
response = await axios({
method,
url,
data: method === 'GET' ? null : data, // Ensure data is null for GET requests
params,
headers,
responseType: "json",
});
}
return response;
} This modification ensures that the Additionally, you can refer to the test case in it('should make a successful request to the application parameter', async () => {
const method = 'GET'
const endpoint = routes.application.url
const expectedResponse = { data: 'response' }
axios.mockResolvedValue(expectedResponse)
await difyClient.sendRequest(method, endpoint)
expect(axios).toHaveBeenCalledWith({
method,
url: `${BASE_URL}${endpoint}`,
data: null, // Ensure data is null for GET requests
params: null,
headers: {
Authorization: `Bearer ${difyClient.apiKey}`,
'Content-Type': 'application/json',
},
responseType: 'json',
})
}) This test case demonstrates that the By making these changes, you can avoid the 400 Bad Request errors caused by sending a body with GET requests on platforms like Google Cloud.
|
Self Checks
Dify version
2.3.1
Cloud or Self Hosted
Self Hosted (Source)
Steps to reproduce
If you are using a base url some platform hosted in gcloud (for example) all GETs request returns 400 Bad Request.
✔️ Expected Behavior
Get should be whitout body
❌ Actual Behavior
Get Requests return 400 malformed request in some scenario like gcloud
The text was updated successfully, but these errors were encountered: