Skip to content

Commit 7507b80

Browse files
committed
Tabify!
1 parent 805f2bb commit 7507b80

File tree

11 files changed

+424
-425
lines changed

11 files changed

+424
-425
lines changed

RestSharp/Authenticators/NtlmAuthenticator.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,36 @@ namespace RestSharp
2626
/// </summary>
2727
public class NtlmAuthenticator : IAuthenticator
2828
{
29-
private readonly ICredentials credentials;
29+
private readonly ICredentials credentials;
3030

31-
/// <summary>
32-
/// Authenticate with the credentials of the currently logged in user
33-
/// </summary>
34-
public NtlmAuthenticator()
35-
: this(CredentialCache.DefaultCredentials)
36-
{
37-
}
31+
/// <summary>
32+
/// Authenticate with the credentials of the currently logged in user
33+
/// </summary>
34+
public NtlmAuthenticator()
35+
: this(CredentialCache.DefaultCredentials)
36+
{
37+
}
3838

39-
/// <summary>
40-
/// Authenticate by impersonation
41-
/// </summary>
42-
/// <param name="username"></param>
43-
/// <param name="password"></param>
44-
public NtlmAuthenticator(string username, string password) : this(new NetworkCredential(username, password))
45-
{
46-
}
39+
/// <summary>
40+
/// Authenticate by impersonation
41+
/// </summary>
42+
/// <param name="username"></param>
43+
/// <param name="password"></param>
44+
public NtlmAuthenticator(string username, string password) : this(new NetworkCredential(username, password))
45+
{
46+
}
4747

48-
/// <summary>
49-
/// Authenticate by impersonation, using an existing <c>ICredentials</c> instance
50-
/// </summary>
51-
/// <param name="credentials"></param>
52-
public NtlmAuthenticator(ICredentials credentials)
53-
{
54-
if (credentials == null) throw new ArgumentNullException("credentials");
55-
this.credentials = credentials;
56-
}
48+
/// <summary>
49+
/// Authenticate by impersonation, using an existing <c>ICredentials</c> instance
50+
/// </summary>
51+
/// <param name="credentials"></param>
52+
public NtlmAuthenticator(ICredentials credentials)
53+
{
54+
if (credentials == null) throw new ArgumentNullException("credentials");
55+
this.credentials = credentials;
56+
}
5757

58-
public void Authenticate(IRestClient client, IRestRequest request)
58+
public void Authenticate(IRestClient client, IRestRequest request)
5959
{
6060
request.Credentials = credentials;
6161
}
Lines changed: 126 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,128 @@
1-
#region License
2-
// Copyright 2010 John Sheehan
3-
//
4-
// Licensed under the Apache License, Version 2.0 (the "License");
5-
// you may not use this file except in compliance with the License.
6-
// You may obtain a copy of the License at
7-
//
8-
// http://www.apache.org/licenses/LICENSE-2.0
9-
//
10-
// Unless required by applicable law or agreed to in writing, software
11-
// distributed under the License is distributed on an "AS IS" BASIS,
12-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
// See the License for the specific language governing permissions and
14-
// limitations under the License.
15-
#endregion
16-
17-
using System.Globalization;
18-
using System.IO;
19-
using System.Text;
20-
21-
namespace RestSharp.Extensions
22-
{
23-
/// <summary>
24-
/// Extension method overload!
25-
/// </summary>
26-
public static class MiscExtensions
27-
{
28-
#if !WINDOWS_PHONE
29-
/// <summary>
30-
/// Save a byte array to a file
31-
/// </summary>
32-
/// <param name="input">Bytes to save</param>
33-
/// <param name="path">Full path to save file to</param>
34-
public static void SaveAs(this byte[] input, string path)
35-
{
36-
File.WriteAllBytes(path, input);
37-
}
38-
#endif
39-
40-
/// <summary>
41-
/// Read a stream into a byte array
42-
/// </summary>
43-
/// <param name="input">Stream to read</param>
44-
/// <returns>byte[]</returns>
45-
public static byte[] ReadAsBytes(this Stream input)
46-
{
47-
byte[] buffer = new byte[16 * 1024];
48-
using (MemoryStream ms = new MemoryStream())
49-
{
50-
int read;
51-
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
52-
{
53-
ms.Write(buffer, 0, read);
54-
}
55-
return ms.ToArray();
56-
}
57-
}
58-
59-
/// <summary>
60-
/// Copies bytes from one stream to another
61-
/// </summary>
62-
/// <param name="input">The input stream.</param>
63-
/// <param name="output">The output stream.</param>
64-
public static void CopyTo(this Stream input, Stream output)
65-
{
66-
var buffer = new byte[32768];
67-
while(true)
68-
{
69-
var read = input.Read(buffer, 0, buffer.Length);
70-
if(read <= 0)
71-
return;
72-
output.Write(buffer, 0, read);
73-
}
74-
}
75-
76-
/// <summary>
77-
/// Converts a byte array to a string, using its byte order mark to convert it to the right encoding.
78-
/// http://www.shrinkrays.net/code-snippets/csharp/an-extension-method-for-converting-a-byte-array-to-a-string.aspx
79-
/// </summary>
80-
/// <param name="buffer">An array of bytes to convert</param>
81-
/// <returns>The byte as a string.</returns>
82-
public static string AsString(this byte[] buffer)
1+
#region License
2+
// Copyright 2010 John Sheehan
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
#endregion
16+
17+
using System.Globalization;
18+
using System.IO;
19+
using System.Text;
20+
21+
namespace RestSharp.Extensions
22+
{
23+
/// <summary>
24+
/// Extension method overload!
25+
/// </summary>
26+
public static class MiscExtensions
27+
{
28+
#if !WINDOWS_PHONE
29+
/// <summary>
30+
/// Save a byte array to a file
31+
/// </summary>
32+
/// <param name="input">Bytes to save</param>
33+
/// <param name="path">Full path to save file to</param>
34+
public static void SaveAs(this byte[] input, string path)
8335
{
84-
if (buffer == null) return "";
85-
86-
// Ansi as default
87-
Encoding encoding = Encoding.UTF8;
88-
89-
#if FRAMEWORK
90-
return encoding.GetString(buffer);
91-
#else
92-
if (buffer == null || buffer.Length == 0)
93-
return "";
94-
95-
/*
96-
EF BB BF UTF-8
97-
FF FE UTF-16 little endian
98-
FE FF UTF-16 big endian
99-
FF FE 00 00 UTF-32, little endian
100-
00 00 FE FF UTF-32, big-endian
101-
*/
102-
103-
if (buffer[0] == 0xef && buffer[1] == 0xbb && buffer[2] == 0xbf)
104-
{
105-
encoding = Encoding.UTF8;
106-
}
107-
else if (buffer[0] == 0xfe && buffer[1] == 0xff)
108-
{
109-
encoding = Encoding.Unicode;
110-
}
111-
else if (buffer[0] == 0xfe && buffer[1] == 0xff)
112-
{
113-
encoding = Encoding.BigEndianUnicode; // utf-16be
114-
}
115-
116-
using (MemoryStream stream = new MemoryStream())
117-
{
118-
stream.Write(buffer, 0, buffer.Length);
119-
stream.Seek(0, SeekOrigin.Begin);
120-
using (StreamReader reader = new StreamReader(stream, encoding))
121-
{
122-
return reader.ReadToEnd();
123-
}
124-
}
125-
#endif
126-
}
127-
}
36+
File.WriteAllBytes(path, input);
37+
}
38+
#endif
39+
40+
/// <summary>
41+
/// Read a stream into a byte array
42+
/// </summary>
43+
/// <param name="input">Stream to read</param>
44+
/// <returns>byte[]</returns>
45+
public static byte[] ReadAsBytes(this Stream input)
46+
{
47+
byte[] buffer = new byte[16 * 1024];
48+
using (MemoryStream ms = new MemoryStream())
49+
{
50+
int read;
51+
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
52+
{
53+
ms.Write(buffer, 0, read);
54+
}
55+
return ms.ToArray();
56+
}
57+
}
58+
59+
/// <summary>
60+
/// Copies bytes from one stream to another
61+
/// </summary>
62+
/// <param name="input">The input stream.</param>
63+
/// <param name="output">The output stream.</param>
64+
public static void CopyTo(this Stream input, Stream output)
65+
{
66+
var buffer = new byte[32768];
67+
while(true)
68+
{
69+
var read = input.Read(buffer, 0, buffer.Length);
70+
if(read <= 0)
71+
return;
72+
output.Write(buffer, 0, read);
73+
}
74+
}
75+
76+
/// <summary>
77+
/// Converts a byte array to a string, using its byte order mark to convert it to the right encoding.
78+
/// http://www.shrinkrays.net/code-snippets/csharp/an-extension-method-for-converting-a-byte-array-to-a-string.aspx
79+
/// </summary>
80+
/// <param name="buffer">An array of bytes to convert</param>
81+
/// <returns>The byte as a string.</returns>
82+
public static string AsString(this byte[] buffer)
83+
{
84+
if (buffer == null) return "";
85+
86+
// Ansi as default
87+
Encoding encoding = Encoding.UTF8;
88+
89+
#if FRAMEWORK
90+
return encoding.GetString(buffer);
91+
#else
92+
if (buffer == null || buffer.Length == 0)
93+
return "";
94+
95+
/*
96+
EF BB BF UTF-8
97+
FF FE UTF-16 little endian
98+
FE FF UTF-16 big endian
99+
FF FE 00 00 UTF-32, little endian
100+
00 00 FE FF UTF-32, big-endian
101+
*/
102+
103+
if (buffer[0] == 0xef && buffer[1] == 0xbb && buffer[2] == 0xbf)
104+
{
105+
encoding = Encoding.UTF8;
106+
}
107+
else if (buffer[0] == 0xfe && buffer[1] == 0xff)
108+
{
109+
encoding = Encoding.Unicode;
110+
}
111+
else if (buffer[0] == 0xfe && buffer[1] == 0xff)
112+
{
113+
encoding = Encoding.BigEndianUnicode; // utf-16be
114+
}
115+
116+
using (MemoryStream stream = new MemoryStream())
117+
{
118+
stream.Write(buffer, 0, buffer.Length);
119+
stream.Seek(0, SeekOrigin.Begin);
120+
using (StreamReader reader = new StreamReader(stream, encoding))
121+
{
122+
return reader.ReadToEnd();
123+
}
124+
}
125+
#endif
126+
}
127+
}
128128
}

RestSharp/Extensions/ResponseExtensions.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55

66
namespace RestSharp.Extensions
77
{
8-
public static class ResponseExtensions
9-
{
10-
public static IRestResponse<T> toAsyncResponse<T>(this IRestResponse response)
11-
{
12-
return new RestResponse<T>
13-
{
14-
ContentEncoding = response.ContentEncoding,
15-
ContentLength = response.ContentLength,
16-
ContentType = response.ContentType,
17-
Cookies = response.Cookies,
18-
ErrorMessage = response.ErrorMessage,
19-
Headers = response.Headers,
20-
RawBytes = response.RawBytes,
21-
ResponseStatus = response.ResponseStatus,
22-
ResponseUri = response.ResponseUri,
23-
Server = response.Server,
24-
StatusCode = response.StatusCode,
25-
StatusDescription = response.StatusDescription
26-
};
27-
}
28-
}
8+
public static class ResponseExtensions
9+
{
10+
public static IRestResponse<T> toAsyncResponse<T>(this IRestResponse response)
11+
{
12+
return new RestResponse<T>
13+
{
14+
ContentEncoding = response.ContentEncoding,
15+
ContentLength = response.ContentLength,
16+
ContentType = response.ContentType,
17+
Cookies = response.Cookies,
18+
ErrorMessage = response.ErrorMessage,
19+
Headers = response.Headers,
20+
RawBytes = response.RawBytes,
21+
ResponseStatus = response.ResponseStatus,
22+
ResponseUri = response.ResponseUri,
23+
Server = response.Server,
24+
StatusCode = response.StatusCode,
25+
StatusDescription = response.StatusDescription
26+
};
27+
}
28+
}
2929
}

0 commit comments

Comments
 (0)