@@ -18,7 +18,6 @@ namespace GeneXus.Application
1818 using Microsoft . AspNetCore . Http ;
1919 using GxClasses . Helpers ;
2020 using Experimental . System . Messaging ;
21- using Microsoft . Net . Http . Headers ;
2221#endif
2322 using GeneXus . Configuration ;
2423 using GeneXus . Metadata ;
@@ -49,6 +48,7 @@ namespace GeneXus.Application
4948 using System . Threading ;
5049 using System . Security . Claims ;
5150 using System . Security ;
51+ using Microsoft . Net . Http . Headers ;
5252
5353 public interface IGxContext
5454 {
@@ -2433,74 +2433,81 @@ private void SetCustomHttpHeader(string name, string value)
24332433 {
24342434 try
24352435 {
2436-
24372436#if ! NETCORE
2438-
2439- switch ( name . ToUpper ( ) )
2440- {
2441- case "CACHE-CONTROL" :
2442- if ( CacheControlHeaderValue . TryParse ( value , out CacheControlHeaderValue parsedValue ) )
2443- {
2444- HttpContext . Current . Response . CacheControl = parsedValue . ToString ( ) ;
2445- }
2446- else
2447- {
2448- var Cache = _HttpContext . Response . Cache ;
2449- string [ ] values = value . Split ( ',' ) ;
2450- foreach ( string v in values )
2451- {
2452- switch ( v . Trim ( ) . ToUpper ( ) )
2453- {
2454- case "PUBLIC" :
2455- Cache . SetCacheability ( HttpCacheability . Public ) ;
2456- break ;
2457- case "PRIVATE" :
2458- Cache . SetCacheability ( HttpCacheability . Private ) ;
2459- break ;
2460- case "NO-CACHE" :
2461- Cache . SetCacheability ( HttpCacheability . NoCache ) ;
2462- break ;
2463- case "NO-STORE" :
2464- Cache . AppendCacheExtension ( "no-store, must-revalidate" ) ;
2465- break ;
2466- default :
2467- GXLogging . Warn ( log , String . Format ( "Could not set Cache Control Http Header Value '{0}' to HttpResponse" , value ) ) ;
2468- break ;
2469- }
2470- }
2471- }
2472- break ;
2473- default :
2474- _HttpContext . Response . Headers [ name ] = value ;
2475- break ;
2476- }
2477- #else
2478- switch ( name . ToUpper ( ) )
2437+
2438+ if ( name . Equals ( HeaderNames . CacheControl , StringComparison . OrdinalIgnoreCase ) )
24792439 {
2480- case "CACHE-CONTROL" :
2481- if ( CacheControlHeaderValue . TryParse ( value , out CacheControlHeaderValue parsedValue ) )
2482- {
2483- _HttpContext . Response . GetTypedHeaders ( ) . CacheControl = parsedValue ;
2484- }
2485- else
2440+ if ( System . Net . Http . Headers . CacheControlHeaderValue . TryParse ( value , out System . Net . Http . Headers . CacheControlHeaderValue parsedValue ) )
2441+ {
2442+ HttpContext . Current . Response . CacheControl = parsedValue . ToString ( ) ;
2443+ }
2444+ else
2445+ {
2446+ var Cache = _HttpContext . Response . Cache ;
2447+ string [ ] values = value . Split ( ',' ) ;
2448+ foreach ( string v in values )
24862449 {
2487- switch ( value . ToUpper ( ) )
2450+ switch ( v . Trim ( ) . ToUpper ( ) )
24882451 {
24892452 case "PUBLIC" :
2490- _HttpContext . Response . AddHeader ( "Cache-Control" , "public" ) ;
2453+ Cache . SetCacheability ( HttpCacheability . Public ) ;
24912454 break ;
24922455 case "PRIVATE" :
2493- _HttpContext . Response . AddHeader ( "Cache-Control" , "private" ) ;
2456+ Cache . SetCacheability ( HttpCacheability . Private ) ;
2457+ break ;
2458+ case "NO-CACHE" :
2459+ Cache . SetCacheability ( HttpCacheability . NoCache ) ;
2460+ break ;
2461+ case "NO-STORE" :
2462+ Cache . AppendCacheExtension ( "no-store, must-revalidate" ) ;
24942463 break ;
24952464 default :
24962465 GXLogging . Warn ( log , String . Format ( "Could not set Cache Control Http Header Value '{0}' to HttpResponse" , value ) ) ;
24972466 break ;
24982467 }
24992468 }
2500- break ;
2501- default :
2469+ }
2470+ }
2471+ else if ( name . Equals ( HeaderNames . ContentType , StringComparison . OrdinalIgnoreCase ) )
2472+ {
2473+ _HttpContext . Response . ContentType = value ;
2474+ }
2475+ else
2476+ {
2477+ if ( ! string . IsNullOrEmpty ( _HttpContext . Response . Headers [ name ] ) )
2478+ {
2479+ _HttpContext . Response . Headers [ name ] = value ;
2480+ }
2481+ else
2482+ {
2483+ _HttpContext . Response . AppendHeader ( name , value ) ;
2484+ }
2485+ }
2486+ #else
2487+ if ( name . Equals ( HeaderNames . CacheControl , StringComparison . OrdinalIgnoreCase ) )
2488+ {
2489+ if ( CacheControlHeaderValue . TryParse ( value , out CacheControlHeaderValue parsedValue ) )
2490+ {
2491+ _HttpContext . Response . GetTypedHeaders ( ) . CacheControl = parsedValue ;
2492+ }
2493+ else
2494+ {
2495+ switch ( value . ToUpper ( ) )
2496+ {
2497+ case "PUBLIC" :
2498+ _HttpContext . Response . AddHeader ( HeaderNames . CacheControl , "public" ) ;
2499+ break ;
2500+ case "PRIVATE" :
2501+ _HttpContext . Response . AddHeader ( HeaderNames . CacheControl , "private" ) ;
2502+ break ;
2503+ default :
2504+ GXLogging . Warn ( log , String . Format ( "Could not set Cache Control Http Header Value '{0}' to HttpResponse" , value ) ) ;
2505+ break ;
2506+ }
2507+ }
2508+ }
2509+ else {
25022510 _HttpContext . Response . AddHeader ( name , value ) ;
2503- break ;
25042511 }
25052512#endif
25062513 }
0 commit comments