Specify Allow header as content header in HttpResponse
Fixes #80 Signed-off-by: Jon Skeet <jonskeet@google.com>
This commit is contained in:
parent
2988a0c5df
commit
e197ef0e36
|
@ -41,10 +41,11 @@ namespace CloudNative.CloudEvents.Http
|
|||
(request, headerName) => request.Headers.TryGetValues(headerName, out var values) ? values.FirstOrDefault() : null,
|
||||
validateOrigin, validateRate);
|
||||
|
||||
var message = new HttpResponseMessage(statusCode);
|
||||
// Note: it's a little odd to create an empty ByteArrayContent, but the Allow header is a content header, so we need content.
|
||||
var message = new HttpResponseMessage(statusCode) { Content = new ByteArrayContent(Array.Empty<byte>()) };
|
||||
if (allowedOrigin is object)
|
||||
{
|
||||
message.Headers.Add("Allow", "POST");
|
||||
message.Content.Headers.Add("Allow", "POST");
|
||||
message.Headers.Add("WebHook-Allowed-Origin", allowedOrigin);
|
||||
if (allowedRate is object)
|
||||
{
|
||||
|
|
|
@ -8,6 +8,7 @@ using CloudNative.CloudEvents.UnitTests;
|
|||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
|
@ -60,6 +61,20 @@ namespace CloudNative.CloudEvents.Http.UnitTests
|
|||
}
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[InlineData("validorigin", HttpStatusCode.OK)]
|
||||
[InlineData("notvalidorigin", HttpStatusCode.MethodNotAllowed)]
|
||||
public async Task HandleAsWebHookValidationRequest_Simple(string origin, HttpStatusCode expectedResponseCode)
|
||||
{
|
||||
var request = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Options,
|
||||
Headers = { { "WebHook-Request-Origin", origin } }
|
||||
};
|
||||
var response = await request.HandleAsWebHookValidationRequest(actualOrigin => actualOrigin == "validorigin", null);
|
||||
Assert.Equal(expectedResponseCode, response.StatusCode);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(SingleCloudEventMessages))]
|
||||
public void IsCloudEvent_True(string description, HttpContent content, IDictionary<string, string> headers)
|
||||
|
|
Loading…
Reference in New Issue