Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Span<Byte> to the HTTP request header in Kestrel

.NET Core now has the efficient Span<T> and related types that allow more efficient memory operations. Also, there are some basic parsing primitives for dealing with Span<Byte> without having to decode UTF-8.

Kestrel can process requests without using string I reckon.

The user of ASP.NET Core, however, gets the request header (request path and HTTP headers) only as strings.

Is there a way to get that as Span<Byte> also? I have a very low-level application where ideally I would want certain requests make no memory allocations. I'm also just curious.

like image 601
John Avatar asked Oct 26 '25 14:10

John


1 Answers

Not at this level, the abstraction for headers is a IHeaderDictionary. Those are parsed before your code runs and we give you a StringValues. There's been various discussions around exposing it as byte[]/Span<byte> but nothing has come of this as yet.

like image 62
davidfowl Avatar answered Oct 28 '25 05:10

davidfowl