This repository has been archived by the owner on Apr 26, 2023. It is now read-only.
This repository has been archived by the owner on Apr 26, 2023. It is now read-only.
Closed
Description
The proxy in my environment is sitting behind a load balancer. The load balancer rejects 304 responses containing a body. According to the HTTP specification 304's should never contain a body:
https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
The context.Response.OutputStream.Write(bytes, 0, bytes.Length); writes bytes to the body of the response that causes to the response to be blocked by our load balancer.
I made a modification to the code in my instance in catch block of the forwardToServer try and made it so no outputStream is written in a 304.
``
System.Net.WebResponse serverResponse = null;
try {
serverResponse = forwardToServer(context.Request, addTokenToUri(requestUri, token, tokenParamName), postBody, credentials);
} catch (System.Net.WebException webExc) {
string errorMsg = webExc.Message + " " + uri;
log(TraceLevel.Error, errorMsg);
if (webExc.Response != null)
{
copyResponseHeaders(webExc.Response as System.Net.HttpWebResponse, context.Response);
using (Stream responseStream = webExc.Response.GetResponseStream())
{
byte[] bytes = new byte[32768];
int bytesRead = 0;
while ((bytesRead = responseStream.Read(bytes, 0, bytes.Length)) > 0)
{
responseStream.Write(bytes, 0, bytesRead);
}
context.Response.StatusCode = (int)(webExc.Response as System.Net.HttpWebResponse).StatusCode;
// ********************
// Code to ensure 304 responses do not contain a body
// ********************
if (context.Response.StatusCode != 304)
{
context.Response.OutputStream.Write(bytes, 0, bytes.Length);
}
}
}