Skip to content

Commit

Permalink
Merge pull request #132 from Readify/issue-131
Browse files Browse the repository at this point in the history
Re #131 - Adds X-Stream header on connection
  • Loading branch information
cskardon committed Nov 20, 2015
2 parents 931302c + 176ba44 commit c801ff1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Neo4jClient.Tests/GraphClientTests/ConnectTests.cs
Expand Up @@ -177,6 +177,64 @@ public void CredentialsPreservedAllTheWayThroughToHttpStack()
StringAssert.AreEqualIgnoringCase("dXNlcm5hbWU6cGFzc3dvcmQ=", httpRequest.Headers.Authorization.Parameter);
}

[Test]
public void PassesCorrectStreamHeader_WhenUseStreamIsTrue()
{
var httpClient = Substitute.For<IHttpClient>();
httpClient
.SendAsync(Arg.Any<HttpRequestMessage>())
.Returns(callInfo => { throw new NotImplementedException(); });

var graphClient = new GraphClient(new Uri("http://username:password@foo/db/data"), httpClient);

try
{
graphClient.Connect();
}
// ReSharper disable EmptyGeneralCatchClause
catch (NotImplementedException)
{
// This will fail because we're not giving it the right
// HTTP response, but we only care about the request for now
}
// ReSharper restore EmptyGeneralCatchClause

var httpCall = httpClient.ReceivedCalls().Last();
var httpRequest = (HttpRequestMessage)httpCall.GetArguments()[0];

Assert.IsTrue(httpRequest.Headers.Contains("X-Stream"));
Assert.Contains("true", httpRequest.Headers.GetValues("X-Stream").ToList());
}

[Test]
public void PassesCorrectStreamHeader_WhenUseStreamIsFalse()
{
var httpClient = Substitute.For<IHttpClient>();
httpClient
.SendAsync(Arg.Any<HttpRequestMessage>())
.Returns(callInfo => { throw new NotImplementedException(); });

var graphClient = new GraphClient(new Uri("http://username:password@foo/db/data"), httpClient);
graphClient.ExecutionConfiguration.UseJsonStreaming = false;
try
{
graphClient.Connect();
}
// ReSharper disable EmptyGeneralCatchClause
catch (NotImplementedException)
{
// This will fail because we're not giving it the right
// HTTP response, but we only care about the request for now
}
// ReSharper restore EmptyGeneralCatchClause

var httpCall = httpClient.ReceivedCalls().Last();
var httpRequest = (HttpRequestMessage)httpCall.GetArguments()[0];

Assert.IsFalse(httpRequest.Headers.Contains("X-Stream"));
}


[Test]
public void ShouldParseRootApiResponseFromAuthenticatedConnection()
{
Expand Down
2 changes: 2 additions & 0 deletions Neo4jClient/Execution/ResponseBuilder.cs
Expand Up @@ -76,6 +76,8 @@ private Task<HttpResponseMessage> PrepareAsync(TaskFactory taskFactory)
_request.Headers.Accept.Clear();
_request.Headers.Remove("Accept");
_request.Headers.Add("Accept", "application/json;stream=true");
_request.Headers.Remove("X-Stream");
_request.Headers.Add("X-Stream", "true");
}

_request.Headers.Add("User-Agent", _executionConfiguration.UserAgent);
Expand Down

0 comments on commit c801ff1

Please sign in to comment.