C
C#2y 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
canton72y ago
Why is this list only returning one item?
Which list, exactly?
devhl
devhlOP2y ago
var a only has one item in it.
mtreit
mtreit2y ago
FirstOrDefault Do you know what that does?
devhl
devhlOP2y ago
ooff okay, lool forest through the trees...
Angius
Angius2y ago
Also, if it returns null, that .Value will throw an exception
devhl
devhlOP2y ago
yeah I was thinking that too.
mtreit
mtreit2y ago
Actually what is the reason to call ToList in this code?
devhl
devhlOP2y 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
mtreit2y ago
I'm not sure where you are seeing public max-age
devhl
devhlOP2y ago
Sometimes the server gives me one or the other. I don't know the difference.
canton7
canton72y 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
devhlOP2y ago
Oooohhhh so the cache control header is one string, and the sub headers are just parsed out of it. got it
canton7
canton72y 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
devhlOP2y ago
Cool thanks. I was doing this wrong. Glad to know.
Accord
Accord2y 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.
Want results from more Discord servers?
Add your server