Moved some code around, for better re-usage. Also added some debug information, and wrote some comments. [skip ci]

This commit is contained in:
Robin 2015-04-15 13:16:26 +02:00
parent 6f8434d46f
commit ea8c27449f
4 changed files with 196 additions and 160 deletions

View file

@ -336,6 +336,20 @@ namespace GreenshotPlugin.Core {
return GetResponse(webRequest);
}
/// <summary>
/// Log the headers of the WebResponse, if IsDebugEnabled
/// </summary>
/// <param name="response">WebResponse</param>
private static void DebugHeaders(WebResponse response) {
if (!LOG.IsDebugEnabled) {
return;
}
LOG.DebugFormat("Debug information on the response from {0} :", response.ResponseUri);
foreach (string key in response.Headers.AllKeys) {
LOG.DebugFormat("Reponse-header: {0}={1}", key, response.Headers[key]);
}
}
/// <summary>
/// Process the web response.
/// </summary>
@ -348,6 +362,7 @@ namespace GreenshotPlugin.Core {
HttpWebResponse response = (HttpWebResponse) webRequest.GetResponse();
LOG.InfoFormat("Response status: {0}", response.StatusCode);
bool isHttpError = (int) response.StatusCode >= 300;
DebugHeaders(response);
Stream responseStream = response.GetResponseStream();
if (responseStream != null) {
using (StreamReader reader = new StreamReader(responseStream, true)) {