-
Notifications
You must be signed in to change notification settings - Fork 1.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
Reroute sending empty Content-Type which causes Bad request #464
Comments
@vasicvuk thanks for your interest in the project! Mmmmmmmm I didn't even realise I'm adding these on...I think the issue is in RequestMapper.cs but not 100%. It looks like the Content-Type header is added there but I cannot find where the Content-Length header is being added. This should be pretty easy to fix and will just need some debugging to work it out. |
Ill try get it fixed asap |
@TomPallister thank you for quick response. I will try to debug it too in order to see where the problem is. |
Seems like HttpRequest by default has System.IO.Stream+NullStream not null. So the headers are added anyway since request.Body is never null.
Still not sure how Content-Length is added but maybe it is added by default if Content-Type is provided. Here is the little test i made to see what is value of body:
This test returns: Body is not null System.IO.Stream+NullStream |
@vasicvuk yep as expected that is the problem area! :) |
The same thing happens when running Ocelot and the API in the same process with aspnet core 2.1 Ocelot adds this empty header causing the API to fail. I have added a middleware to remove this empty header to avoid this problem |
@vasicvuk sorry I have not fixed this yet, I have been away for a few days! Will get on it ASAP. |
@vasicvuk what are you hosting Ocelot with e.g. Linux / Windows? Is there anything in front of Kestrel e.g. IIS / nginx? When I debug Ocelot I Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameRequestStream as the type for a stream when I curl with GET so no body. I think there is might be some .net core magic here to contend with! |
There are also ConentType and ContentLength properties on the request object...I guess I could use them to say if they don't exist then definitely don't add any content. |
I use ASP.Net Core 2.1 running it with IIS through Visual Studio 2017 Community on Windows 10 64 bit. |
Ok cool, I will keep looking! |
I guess that you can trim it when Content-Length is 0 but it would be nice to know what is causing an issue |
@vasicvuk I think NullStream is an internal type so you cant check or instantiate it. I also think it is only set when you instantiate DefaultHttpRequest...not when you receive an actual HttpRequest! |
…pe and content length headers, .net will automatically try and add these headers in a few circumstances but this solves the 464 issue
* #464 added code to request mapper to not automatically add content type and content length headers, .net will automatically try and add these headers in a few circumstances but this solves the 464 issue * #464 use seek instead of read on body check for websockets tests * #464 ran out of inodes on linux, looks like reloadonchange causes this
Released in version 8.0.1 |
Confirming that everything works now! 👍 |
sweet |
Expected Behavior / New Feature
When sending Http get request from ocelot to downstream. Content-Type should not be sent.
Actual Behavior / Motivation for New Feautre
Currently there is an empty Content-Type header sent. Also Content-Length: 0 is extra too. This causes for most APIs made in Java to give 400 Bad request since they don't have formatter for Content-Type empty string. Sample:
Steps to Reproduce the Problem
Specifications
The text was updated successfully, but these errors were encountered: