Skip to content

Commit

Permalink
support added for restsharp#781: ability to set HttpHeader 'Connectio…
Browse files Browse the repository at this point in the history
…n' to 'keep-alive' or 'close' using the existing header dictionary
  • Loading branch information
matthewberkland committed Mar 22, 2016
1 parent 80c1e49 commit 09292a7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion RestSharp/Http.Sync.cs
Expand Up @@ -139,7 +139,13 @@ private HttpResponse PostPutInternal(string method)

partial void AddSyncHeaderActions()
{
this.restrictedHeaderActions.Add("Connection", (r, v) => r.Connection = v);
//this.restrictedHeaderActions.Add("Connection", (r, v) => r.Connection = v);
this.restrictedHeaderActions.Add("Connection", (r, v) => {
if (v.ToLower().Contains("keep-alive"))
r.KeepAlive = true; //if a user sets the connection header explicitly to "keep-alive" then we set the field on HttpWebRequest
else
r.KeepAlive = false; //if "Connection" is specified as anything else, we turn off keep alive functions
});
this.restrictedHeaderActions.Add("Content-Length", (r, v) => r.ContentLength = Convert.ToInt64(v));
this.restrictedHeaderActions.Add("Expect", (r, v) => r.Expect = v);
this.restrictedHeaderActions.Add("If-Modified-Since", (r, v) => r.IfModifiedSince = Convert.ToDateTime(v));
Expand Down

0 comments on commit 09292a7

Please sign in to comment.