Exemple #1
0
        public static void SetFileHeaders(this ResponseHeaders headers,
                                          string fileName, string contentType, bool?inline)
        {
            if (contentType.HasBlackSpace())
            {
                if (MediaTypeHeaderValue.TryParse(contentType, out MediaTypeHeaderValue contentTypeHeader))
                {
                    headers.ContentType = contentTypeHeader;
                }
            }

            if (fileName.HasBlackSpace())
            {
                var dispositionType = GetDispositiontype();
                headers.ContentDisposition = new ContentDispositionHeaderValue(dispositionType)
                {
                    FileName = fileName,
                };

                string GetDispositiontype()
                {
                    if (inline.HasValue)
                    {
                        if (inline.Value)
                        {
                            return("inline");
                        }
                    }

                    return("attachment");
                }
            }
        }
Exemple #2
0
 private void CheckInvalidTryParse(string?input)
 {
     Assert.False(MediaTypeHeaderValue.TryParse(input, out var result));
     Assert.Null(result);
 }
Exemple #3
0
 private void CheckValidTryParse(string?input, MediaTypeHeaderValue expectedResult)
 {
     Assert.True(MediaTypeHeaderValue.TryParse(input, out var result));
     Assert.Equal(expectedResult, result);
 }