Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'kolosy', and cleaned up postStream in CouchRequest.

  • Loading branch information...
commit 1e0e5196b47d6238b8ef60412d0d4c91c37534ea 2 parents c72aa7d + 0ad1376
@gokr gokr authored
View
8 Tests/CouchTest.cs
@@ -205,7 +205,7 @@ public void ShouldSaveDocumentWithoutId()
private class LittleCar
{
- public string Id, Rev;
+ public string _id, _rev;
public string Make, Model, docType;
}
@@ -214,7 +214,7 @@ public void ShouldSaveArbitraryDocument()
{
var littleCar = new LittleCar() { docType = "car", Make = "Yugo", Model = "Hell if i know" };
littleCar = db.SaveArbitraryDocument(littleCar);
- Assert.IsNotNull(littleCar.Id);
+ Assert.IsNotNull(littleCar._id);
}
[Test]
@@ -222,9 +222,9 @@ public void ShouldLoadArbitraryDocument()
{
var firstCar = new LittleCar() { docType = "car", Make = "Yugo", Model = "Hell if i know" };
firstCar = db.SaveArbitraryDocument(firstCar);
- var otherCar = db.GetArbitraryDocument<LittleCar>(firstCar.Id, () => new LittleCar());
+ var otherCar = db.GetArbitraryDocument<LittleCar>(firstCar._id, () => new LittleCar());
Assert.IsNotNull(otherCar);
- Assert.IsNotNull(otherCar.Id);
+ Assert.IsNotNull(otherCar._id);
}
[Test]
View
3  Tests/Divan.Test.csproj
@@ -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
@@ -227,7 +227,7 @@ public ICouchDocument SaveDocument(ICouchDocument document)
else
savedDoc = WriteDocument(document);
}
- catch (CouchConflictException ex)
+ catch (CouchConflictException)
{
if (reconcilingDoc == null)
throw;
View
18 src/CouchRequest.cs
@@ -27,7 +27,6 @@ public class CouchRequest
public string method = "GET"; // PUT, DELETE, POST, HEAD
public string mimeType;
public string path;
- //public byte[] postData;
public string query;
public JToken result;
@@ -134,22 +133,18 @@ public CouchRequest Delete()
public CouchRequest Data(string data)
{
- var postData = Encoding.UTF8.GetBytes(data);
- return Data(postData);
- //this.postStream = new MemoryStream(postData);
- //return this;
+ return Data(Encoding.UTF8.GetBytes(data));
}
public CouchRequest Data(byte[] data)
{
- this.postStream = new MemoryStream(data);
- //postData = data;
+ postStream = new MemoryStream(data);
return this;
}
public CouchRequest Data(Stream dataStream)
{
- this.postStream = dataStream;
+ postStream = dataStream;
return this;
}
@@ -202,7 +197,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)
{
@@ -221,6 +216,11 @@ private HttpWebRequest GetRequest()
request.Headers.Add(header.Key, header.Value);
}
+ if (!string.IsNullOrEmpty(server.EncodedCredentials))
+ {
+ request.Headers.Add("Authorization", server.EncodedCredentials);
+ }
+
if (postStream != null)
{
WriteData(request);
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)
{
Please sign in to comment.
Something went wrong with that request. Please try again.