aspnet / HttpAbstractions

[Archived] HTTP abstractions such as HttpRequest, HttpResponse, and HttpContext, as well as common web utilities. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
382 stars 193 forks source link

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

Closed xakepbean closed 6 years ago

xakepbean commented 6 years ago

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)

benaadams commented 6 years ago

0x09 is TAB not (space)

xakepbean commented 6 years ago

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

benaadams commented 6 years ago

Was just pointing out

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

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

xakepbean commented 6 years ago

Sorry, I was wrong

benaadams commented 6 years ago

Its this issue btw https://github.com/aspnet/KestrelHttpServer/issues/1144