Skip to content

Commit 09292a7

Browse files
support added for restsharp#781: ability to set HttpHeader 'Connection' to 'keep-alive' or 'close' using the existing header dictionary
1 parent 80c1e49 commit 09292a7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

RestSharp/Http.Sync.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ private HttpResponse PostPutInternal(string method)
139139

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

0 commit comments

Comments
 (0)