| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Net; |
| | | 5 | | using CoreWCF.Runtime; |
| | | 6 | | using Microsoft.AspNetCore.Http; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Channels |
| | | 9 | | { |
| | | 10 | | public sealed class HttpRequestMessageProperty : IMessageProperty |
| | | 11 | | { |
| | | 12 | | private readonly HttpContextBackedProperty _httpContextBackedProperty; |
| | | 13 | | |
| | 648 | 14 | | internal HttpRequestMessageProperty(HttpContext httpContext) |
| | | 15 | | { |
| | 648 | 16 | | _httpContextBackedProperty = new HttpContextBackedProperty(httpContext); |
| | 648 | 17 | | } |
| | | 18 | | |
| | | 19 | | public const string Name = "httpRequest"; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Gets the headers from the underlying HTTP Request. |
| | | 23 | | /// </summary> |
| | 16 | 24 | | public WebHeaderCollection Headers => _httpContextBackedProperty.Headers; |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets the method from the underlying HTTP Request. |
| | | 28 | | /// </summary> |
| | 35 | 29 | | public string Method => _httpContextBackedProperty.Method; |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Gets the query string from the underlying HTTP Request. |
| | | 33 | | /// </summary> |
| | | 34 | | /// <remarks>The leading '?' is removed.</remarks> |
| | 0 | 35 | | public string QueryString => _httpContextBackedProperty.QueryString; |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// The entity body is suppressed is the underlying HTTP request has a zero ContentLength. |
| | | 39 | | /// </summary> |
| | | 40 | | /// <value><c>true</c> if [suppress entity body]; otherwise, <c>false</c>.</value> |
| | 0 | 41 | | public bool SuppressEntityBody => _httpContextBackedProperty.SuppressEntityBody; |
| | | 42 | | |
| | | 43 | | IMessageProperty IMessageProperty.CreateCopy() |
| | | 44 | | { |
| | 648 | 45 | | return this; |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | private class HttpContextBackedProperty |
| | | 49 | | { |
| | 648 | 50 | | public HttpContextBackedProperty(HttpContext httpContext) |
| | | 51 | | { |
| | | 52 | | Fx.Assert(httpContext != null, "The 'httpResponseMessage' property should never be null."); |
| | | 53 | | |
| | 648 | 54 | | HttpContext = httpContext; |
| | 648 | 55 | | } |
| | | 56 | | |
| | 696 | 57 | | public HttpContext HttpContext { get; private set; } |
| | | 58 | | |
| | | 59 | | private WebHeaderCollection _headers; |
| | | 60 | | |
| | | 61 | | public WebHeaderCollection Headers |
| | | 62 | | { |
| | | 63 | | get |
| | | 64 | | { |
| | 16 | 65 | | if (_headers == null) |
| | | 66 | | { |
| | 13 | 67 | | _headers = HttpContext.Request.ToWebHeaderCollection(); |
| | | 68 | | } |
| | | 69 | | |
| | 16 | 70 | | return _headers; |
| | | 71 | | } |
| | | 72 | | } |
| | | 73 | | |
| | 35 | 74 | | public string Method => HttpContext.Request.Method; |
| | | 75 | | |
| | | 76 | | public string QueryString |
| | | 77 | | { |
| | | 78 | | get |
| | | 79 | | { |
| | 0 | 80 | | string query = HttpContext.Request.QueryString.Value; |
| | 0 | 81 | | return query.Length == 0 ? string.Empty : query.Substring(1); |
| | | 82 | | } |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | public bool SuppressEntityBody |
| | | 86 | | { |
| | | 87 | | get |
| | | 88 | | { |
| | 0 | 89 | | long? contentLength = HttpContext.Request.ContentLength; |
| | | 90 | | |
| | 0 | 91 | | if (!contentLength.HasValue || |
| | 0 | 92 | | (contentLength.HasValue && contentLength.Value > 0)) |
| | | 93 | | { |
| | 0 | 94 | | return false; |
| | | 95 | | } |
| | | 96 | | |
| | 0 | 97 | | return true; |
| | | 98 | | } |
| | | 99 | | } |
| | | 100 | | } |
| | | 101 | | } |
| | | 102 | | } |