C
C#3y ago
devhl

❔ HttpResponse CacheHeaders

I have two questions. Why is this list only returning one item? Also, the server gives me public max-age and sometimes it is max-age. Will Headers.CacheControl.MaxAge work with both?
15 Replies
canton7
canton73y ago
Why is this list only returning one item?
Which list, exactly?
devhl
devhlOP3y ago
var a only has one item in it.
mtreit
mtreit3y ago
FirstOrDefault Do you know what that does?
devhl
devhlOP3y ago
ooff okay, lool forest through the trees...
Angius
Angius3y ago
Also, if it returns null, that .Value will throw an exception
devhl
devhlOP3y ago
yeah I was thinking that too.
mtreit
mtreit3y ago
Actually what is the reason to call ToList in this code?
devhl
devhlOP3y ago
Only question left is the public max-age and max-age. Do they both show up under Headers.CacheControl.MaxAge var a is just a test
mtreit
mtreit3y ago
I'm not sure where you are seeing public max-age
devhl
devhlOP3y ago
Sometimes the server gives me one or the other. I don't know the difference.
canton7
canton73y ago
https://learn.microsoft.com/en-us/dotnet/api/system.net.http.headers.cachecontrolheadervalue.public?view=net-7.0
This property represents the "public" directive in a cache-control header field on an HTTP response.
So the public shows up as Headers.CachControl.Public being true/false
devhl
devhlOP3y ago
Oooohhhh so the cache control header is one string, and the sub headers are just parsed out of it. got it
canton7
canton73y ago
The public and max-age are called directives: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#cache_directives And yeah, they're parsed out separately
devhl
devhlOP3y ago
Cool thanks. I was doing this wrong. Glad to know.
Accord
Accord3y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?