Beispiel #1
0
        private static void CopyHeadersToHttpListener(SerialisableResponse response, IHeaderCollection responseHeaders, string rebaseEndpoint)
        {
            if (response == null || response.Headers == null)
            {
                return;
            }

            response.Headers.Remove("Pragma");
            response.Headers.Add("Server", new[] { string.Empty });
            response.Headers.Remove("X-Powered-By");

            foreach (var pair in response.Headers)
            {
                // Header filters:
                switch (pair.Key)
                {
                // Skip headers we MUST NOT change:
                case "Transfer-Encoding":  // prevent mismatch of Chunked encoding from breaking things
                case "Content-Length":     // we handle this one specially
                    continue;

                // Filter out vanity headers:
                case "Pragma":
                case "Server":
                case "X-Powered-By":
                case "Via":
                    continue;
                }

                if (pair.Key == "Location")
                {
                    if (Uri.TryCreate(string.Join(",", pair.Value), UriKind.Absolute, out var redirectUrl))
                    {
                        if (redirectUrl.Host == "0.0.0.0")  // local redirect. Pass back the *external* url
                        {
                            var newTarget = rebaseEndpoint + redirectUrl.PathAndQuery;
                            responseHeaders[pair.Key] = newTarget;
                            continue;
                        }
                    }
                }

                if (responseHeaders[pair.Key] == null)
                {
                    responseHeaders[pair.Key] = string.Join(",", pair.Value);
                }
                else
                {
                    responseHeaders.Add(pair.Key, string.Join(", ", pair.Value));
                }
            }
        }
Beispiel #2
0
 private UnknownResponse(IHeaderCollection headers = null)
 {
     _headers = headers ?? new HeaderCollection().Add("Content-Type", "application/json; charset=utf-8");
     _headers.Add("Warning", "Request was not recognized as one of the registered pacts.");
 }