Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 9c08874

Browse files
committed
Expect 100 fix
1 parent 0c997fd commit 9c08874

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Titanium.Web.Proxy/Network/HttpWebClient.cs

+24
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,27 @@ public void SendRequest()
324324
stream.Write(requestBytes, 0, requestBytes.Length);
325325
stream.Flush();
326326

327+
if (ProxyServer.Enable100ContinueBehaviour)
328+
if (this.Request.ExpectContinue)
329+
{
330+
var httpResult = ProxyClient.ServerStreamReader.ReadLine().Split(new char[] { ' ' }, 3);
331+
var responseStatusCode = httpResult[1].Trim();
332+
var responseStatusDescription = httpResult[2].Trim();
333+
334+
//find if server is willing for expect continue
335+
if (responseStatusCode.Equals("100")
336+
&& responseStatusDescription.ToLower().Equals("continue"))
337+
{
338+
this.Request.Is100Continue = true;
339+
ProxyClient.ServerStreamReader.ReadLine();
340+
}
341+
else if (responseStatusCode.Equals("417")
342+
&& responseStatusDescription.ToLower().Equals("expectation failed"))
343+
{
344+
this.Request.ExpectationFailed = true;
345+
ProxyClient.ServerStreamReader.ReadLine();
346+
}
347+
}
327348
}
328349

329350
public void ReceiveResponse()
@@ -342,6 +363,7 @@ public void ReceiveResponse()
342363
this.Response.ResponseStatusCode = httpResult[1].Trim();
343364
this.Response.ResponseStatusDescription = httpResult[2].Trim();
344365

366+
//For HTTP 1.1 comptibility server may send expect-continue even if not asked for it in request
345367
if (this.Response.ResponseStatusCode.Equals("100")
346368
&& this.Response.ResponseStatusDescription.ToLower().Equals("continue"))
347369
{
@@ -351,6 +373,8 @@ public void ReceiveResponse()
351373
ReceiveResponse();
352374
return;
353375
}
376+
else if (this.Response.ResponseStatusCode.Equals("417")
377+
&& this.Response.ResponseStatusDescription.ToLower().Equals("expectation failed"))
354378
{
355379
this.Response.ExpectationFailed = true;
356380
this.Response.ResponseStatusCode = null;

0 commit comments

Comments
 (0)