Skip to content

Commit

Permalink
Merge pull request #136 from ChilliCream/get-request
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Jun 26, 2018
2 parents 1ec7eae + 10bb742 commit e1ccfdf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/AspNetCore.Tests/QueryMiddlewareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ public async Task HttpGet_BasicTest()
Assert.Equal(Snapshot.Current(), Snapshot.New(result));
}

[Fact]
public async Task HttpGet_ForwardToNextMiddleware()
{
// arrange
TestServer server = CreateTestServer();
string query = "{ basic { a } }";

// act
HttpResponseMessage message = await server.CreateClient()
.GetAsync($"http://localhost:5000/1234");

// assert
Assert.Equal(HttpStatusCode.NotFound, message.StatusCode);
}

[Fact]
public async Task HttpPost_WithScalarVariables()
{
Expand Down
18 changes: 10 additions & 8 deletions src/AspNetCore/GetRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ internal static class GetRequest

internal static bool IsGet(this HttpRequest request)
{
return request.Method.Equals(_getMethod, StringComparison.OrdinalIgnoreCase);
return request.Method.Equals(_getMethod, StringComparison.OrdinalIgnoreCase)
&& HasQueryParameter(request.HttpContext);
}

internal static QueryRequest ReadRequest(HttpContext context)
{
string query = string.Empty;

if (context.Request.QueryString.HasValue &&
context.Request.Query.ContainsKey(_queryIdentifier))
return new QueryRequest()
{
query = context.Request.Query[_queryIdentifier].ToString();
}
Query = context.Request.Query[_queryIdentifier].ToString()
};
}

return new QueryRequest() {Query = query};
private static bool HasQueryParameter(HttpContext context)
{
return context.Request.QueryString.HasValue &&
context.Request.Query.ContainsKey(_queryIdentifier);
}
}
}

0 comments on commit e1ccfdf

Please sign in to comment.