Skip to content
Browse files

authentication support

  • Loading branch information...
1 parent 27ec922 commit 0ad1376e9a2a42284620c5da997756b1e5a70b85 @kolosy kolosy committed Nov 25, 2009
Showing with 22 additions and 7 deletions.
  1. +1 −4 Tests/Divan.Test.csproj
  2. +1 −1 src/CouchDatabase.cs
  3. +4 −1 src/CouchRequest.cs
  4. +16 −1 src/CouchServer.cs
View
5 Tests/Divan.Test.csproj
@@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.30729</ProductVersion>
+ <ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{09FB3192-8F25-4112-A8BB-93C83F6C3DDD}</ProjectGuid>
<OutputType>Library</OutputType>
@@ -76,9 +76,6 @@
<Name>Divan</Name>
</ProjectReference>
</ItemGroup>
- <ItemGroup>
- <None Include="App.config" />
- </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
2 src/CouchDatabase.cs
@@ -226,7 +226,7 @@ public ICouchDocument SaveDocument(ICouchDocument document)
savedDoc = WriteDocument(document);
}
- catch (CouchConflictException ex)
+ catch (CouchConflictException)
{
if (reconcilingDoc == null)
throw;
View
5 src/CouchRequest.cs
@@ -191,7 +191,7 @@ public CouchRequest Check(string message)
private HttpWebRequest GetRequest()
{
- Uri requestUri = new UriBuilder("http", server.Host, server.Port, ((db != null) ? db.Name + "/" : "") + path, query).Uri;
+ var requestUri = new UriBuilder("http", server.Host, server.Port, ((db != null) ? db.Name + "/" : "") + path, query).Uri;
var request = WebRequest.Create(requestUri) as HttpWebRequest;
if (request == null)
{
@@ -210,6 +210,9 @@ private HttpWebRequest GetRequest()
request.Headers.Add(header.Key, header.Value);
}
+ if (!string.IsNullOrEmpty(server.EncodedCredentials))
+ request.Headers.Add("Authorization", server.EncodedCredentials);
+
if (postData != null)
{
//byte[] bytes = Encoding.UTF8.GetBytes(postData);
View
17 src/CouchServer.cs
@@ -3,6 +3,7 @@
using System.Diagnostics;
using System.IO;
using System.Net;
+using System.Text;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
@@ -25,16 +26,30 @@ public class CouchServer
public readonly string Host;
public readonly int Port;
+ public readonly string UserName;
+ public readonly string Password;
+ public readonly string EncodedCredentials;
+
public string DatabasePrefix = ""; // Used by databases to prefix their names
- public CouchServer(string host, int port)
+ public CouchServer(string host, int port, string user, string pass)
{
Host = host;
Port = port;
+ UserName = user;
+ Password = pass;
+
+ if (!String.IsNullOrEmpty(UserName))
+ EncodedCredentials = "Basic " +
+ Convert.ToBase64String(Encoding.ASCII.GetBytes(UserName + ":" + Password));
Debug(string.Format("CouchServer({0}:{1})", host, port));
}
+ public CouchServer(string host, int port): this(host, port, null, null)
+ {
+ }
+
public CouchServer(string host)
: this(host, DefaultPort)
{

0 comments on commit 0ad1376

Please sign in to comment.
Something went wrong with that request. Please try again.