Skip to content
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

Timeout and virtual Get/Post #2

Merged
merged 2 commits into from Dec 22, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/EasyHttp/Http/HttpClient.cs
Expand Up @@ -119,7 +119,7 @@ public HttpResponse GetAsFile(string uri, string filename)
return ProcessRequest();
}

public HttpResponse Get(string uri)
public virtual HttpResponse Get(string uri)
{
InitRequest(uri, HttpMethod.GET);
return ProcessRequest();
Expand All @@ -131,7 +131,7 @@ public HttpResponse Options(string uri)
return ProcessRequest();
}

public HttpResponse Post(string uri, object data, string contentType)
public virtual HttpResponse Post(string uri, object data, string contentType)
{
InitRequest(uri, HttpMethod.POST);
InitData(data, contentType);
Expand All @@ -145,7 +145,7 @@ public HttpResponse Patch(string uri, object data, string contentType)
return ProcessRequest();
}

public HttpResponse Post(string uri, IDictionary<string, object> formData, IList<FileData> files)
public virtual HttpResponse Post(string uri, IDictionary<string, object> formData, IList<FileData> files)
{
InitRequest(uri, HttpMethod.POST);
Request.MultiPartFormData = formData;
Expand Down
11 changes: 10 additions & 1 deletion src/EasyHttp/Http/HttpRequest.cs
Expand Up @@ -101,6 +101,7 @@ public class HttpRequest
public string PutFilename { get; set; }
public IDictionary<string, object> MultiPartFormData { get; set; }
public IList<FileData> MultiPartFileData { get; set; }
public int Timeout { get; set; }

HttpWebRequest httpWebRequest;

Expand All @@ -120,6 +121,8 @@ public HttpRequest(IEncoder encoder)
Accept = String.Join(";", HttpContentTypes.TextHtml, HttpContentTypes.ApplicationXml,
HttpContentTypes.ApplicationJson);
_encoder = encoder;

Timeout = 100000; //http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout.aspx
}


Expand All @@ -141,9 +144,15 @@ void SetupHeader()
httpWebRequest.Referer = Referer;
httpWebRequest.CachePolicy = _cachePolicy;
httpWebRequest.KeepAlive = KeepAlive;

ServicePointManager.Expect100Continue = Expect;
ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;

if (Timeout > 0)
{
httpWebRequest.Timeout = Timeout;
}


if (Cookies != null )
{
Expand Down