Skip to content

Commit 0f993ce

Browse files
committed
Cleanup HTTPServer and more stuff
1 parent 0cefd0a commit 0f993ce

File tree

2 files changed

+10
-36
lines changed

2 files changed

+10
-36
lines changed

SpotifyAPI.Example/WebControl.cs

-25
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace SpotifyAPI.Example
1616
public partial class WebControl : UserControl
1717
{
1818
private SpotifyWebAPI _spotify;
19-
private ImplicitGrantAuth _auth;
2019

2120
private PrivateProfile _profile;
2221
private List<FullTrack> _savedTracks;
@@ -30,30 +29,6 @@ public WebControl()
3029

3130
}
3231

33-
private void _auth_OnResponseReceivedEvent(Token token, string state)
34-
{
35-
_auth.StopHttpServer();
36-
37-
if (state != "XSS")
38-
{
39-
MessageBox.Show(@"Wrong state received.", @"SpotifyWeb API Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
40-
return;
41-
}
42-
if (token.Error != null)
43-
{
44-
MessageBox.Show($"Error: {token.Error}", @"SpotifyWeb API Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
45-
return;
46-
}
47-
48-
_spotify = new SpotifyWebAPI
49-
{
50-
UseAuth = true,
51-
AccessToken = token.AccessToken,
52-
TokenType = token.TokenType
53-
};
54-
55-
}
56-
5732
private async void InitialSetup()
5833
{
5934
if (InvokeRequired)

SpotifyAPI/Web/SimpleHttpServer.cs

+10-11
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ public class HttpProcessor : IDisposable
2525
private const int BufSize = 4096;
2626
private readonly HttpServer _srv;
2727
private Stream _inputStream;
28-
public Hashtable HttpHeaders = new Hashtable();
29-
public string HttpMethod;
28+
private readonly Hashtable _httpHeaders = new Hashtable();
29+
private string _httpMethod;
3030
public string HttpProtocolVersionstring;
3131
public string HttpUrl;
3232
public StreamWriter OutputStream;
33-
private bool _isActive = true;
3433

3534
public HttpProcessor(HttpServer srv)
3635
{
@@ -61,16 +60,16 @@ public void Process(TcpClient socket)
6160
ParseRequest(requestLines.First());
6261
ReadHeaders(requestLines.Skip(1));
6362

64-
if (HttpMethod.Equals("GET"))
63+
if (_httpMethod.Equals("GET"))
6564
{
6665
HandleGetRequest();
6766
}
68-
else if (HttpMethod.Equals("POST"))
67+
else if (_httpMethod.Equals("POST"))
6968
{
7069
HandlePostRequest();
7170
}
7271
}
73-
catch (Exception ex)
72+
catch (Exception)
7473
{
7574
WriteFailure();
7675
}
@@ -86,7 +85,7 @@ public void ParseRequest(string request)
8685
{
8786
throw new Exception("Invalid HTTP request line");
8887
}
89-
HttpMethod = tokens[0].ToUpper();
88+
_httpMethod = tokens[0].ToUpper();
9089
HttpUrl = tokens[1];
9190
}
9291

@@ -112,7 +111,7 @@ public void ReadHeaders(IEnumerable<string> requestLines)
112111
}
113112

114113
string value = line.Substring(pos, line.Length - pos);
115-
HttpHeaders[name] = value;
114+
_httpHeaders[name] = value;
116115
}
117116
}
118117

@@ -130,9 +129,9 @@ public void HandlePostRequest()
130129
// length, because otherwise he won't know when he's seen it all!
131130

132131
MemoryStream ms = new MemoryStream();
133-
if (HttpHeaders.ContainsKey("Content-Length"))
132+
if (_httpHeaders.ContainsKey("Content-Length"))
134133
{
135-
var contentLen = Convert.ToInt32(HttpHeaders["Content-Length"]);
134+
var contentLen = Convert.ToInt32(_httpHeaders["Content-Length"]);
136135
if (contentLen > MaxPostSize)
137136
{
138137
throw new Exception($"POST Content-Length({contentLen}) too big for this simple server");
@@ -175,7 +174,7 @@ public void WriteFailure()
175174

176175
public void Dispose()
177176
{
178-
_isActive = false;
177+
179178
}
180179
}
181180

0 commit comments

Comments
 (0)