aspnet/HttpAbstractions

Download file, if the file name starts with a space, an exception occurs, ContentDispositionHeaderValue can automatically remove the head space

xakepbean opened this issue · 5 comments

System.InvalidOperationException: Invalid non-ASCII or control character in header: 0x0009 at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders.ThrowInvalidHeaderCharacter(Char ch) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders.ValidateHeaderCharacters(String headerCharacters) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders.ValidateHeaderCharacters(StringValues headerValues) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameResponseHeaders.SetValueFast(String key, StringValues value) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders.Microsoft.AspNetCore.Http.IHeaderDictionary.set_Item(String key, StringValues value) at Microsoft.AspNetCore.Mvc.Internal.FileResultExecutorBase.SetContentDispositionHeader(ActionContext context, FileResult result) at Microsoft.AspNetCore.Mvc.Internal.FileResultExecutorBase.SetHeadersAndLog(ActionContext context, FileResult result, Nullable1 fileLength, Nullable1 lastModified, EntityTagHeaderValue etag) at Microsoft.AspNetCore.Mvc.Internal.FileContentResultExecutor.ExecuteAsync(ActionContext context, FileContentResult result)

0x09 is TAB not (space)

I use the source code for debugging, it is indeed the beginning of a space caused.
The temporary solution is to TrimStart () file name, the program can be downloaded normally

Was just pointing out

 Invalid non-ASCII or control character in header: 0x0009

Is a TAB charater; space would be 0x0020 and allowed

Sorry, I was wrong