Skip to content

Commit d3f487c

Browse files
committed
Clean up SimpleServer class.
1 parent fb9472b commit d3f487c

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed
Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,57 @@
1-
using System;
2-
using System.Net;
3-
using System.Threading;
4-
5-
namespace RestSharp.IntegrationTests.Helpers
1+
namespace RestSharp.IntegrationTests.Helpers
62
{
3+
using System;
4+
using System.Net;
5+
using System.Threading;
6+
77
public class SimpleServer : IDisposable
88
{
9-
private readonly HttpListener _listener;
10-
private readonly Action<HttpListenerContext> _handler;
11-
private Thread _processor;
9+
private readonly HttpListener listener;
10+
private readonly Action<HttpListenerContext> handler;
11+
private Thread processor;
1212

13-
public static SimpleServer Create(string url, Action<HttpListenerContext> handler,
13+
public static SimpleServer Create(
14+
string url,
15+
Action<HttpListenerContext> handler,
1416
AuthenticationSchemes authenticationSchemes = AuthenticationSchemes.Anonymous)
1517
{
16-
var listener = new HttpListener
17-
{
18-
Prefixes = {url},
19-
AuthenticationSchemes = authenticationSchemes
20-
};
18+
var listener = new HttpListener { Prefixes = { url }, AuthenticationSchemes = authenticationSchemes };
2119
var server = new SimpleServer(listener, handler);
2220

2321
server.Start();
24-
2522
return server;
2623
}
2724

2825
private SimpleServer(HttpListener listener, Action<HttpListenerContext> handler)
2926
{
30-
_listener = listener;
31-
_handler = handler;
27+
this.listener = listener;
28+
this.handler = handler;
3229
}
3330

3431
public void Start()
3532
{
36-
if (!_listener.IsListening)
33+
if (this.listener.IsListening)
3734
{
38-
_listener.Start();
35+
return;
36+
}
3937

40-
_processor = new Thread(() =>
41-
{
42-
var context = _listener.GetContext();
43-
_handler(context);
44-
context.Response.Close();
45-
}) {Name = "WebServer"};
38+
this.listener.Start();
4639

47-
_processor.Start();
48-
}
40+
this.processor = new Thread(() =>
41+
{
42+
var context = this.listener.GetContext();
43+
this.handler(context);
44+
context.Response.Close();
45+
}) { Name = "WebServer" };
46+
47+
this.processor.Start();
4948
}
5049

5150
public void Dispose()
5251
{
53-
_processor.Abort();
54-
_listener.Stop();
55-
_listener.Close();
52+
this.processor.Abort();
53+
this.listener.Stop();
54+
this.listener.Close();
5655
}
5756
}
5857
}

0 commit comments

Comments
 (0)