@@ -2425,62 +2425,59 @@ public byte SetHeader(string name, string value)
24252425 _httpHeaders = new NameValueCollection ( ) ;
24262426 }
24272427 _httpHeaders [ name ] = value ;
2428- SetCustomHttpHeader ( name , value ) ;
2429- return 0 ;
2428+ return SetCustomHttpHeader ( name , value ) ;
24302429 }
24312430
2432- private void SetCustomHttpHeader ( string name , string value )
2431+ private byte SetCustomHttpHeader ( string name , string value )
24332432 {
24342433 try
24352434 {
24362435#if ! NETCORE
24372436
24382437 if ( name . Equals ( HeaderNames . CacheControl , StringComparison . OrdinalIgnoreCase ) )
24392438 {
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
2439+ var Cache = _HttpContext . Response . Cache ;
2440+ string [ ] values = value . Split ( ',' ) ;
2441+ foreach ( string v in values )
24452442 {
2446- var Cache = _HttpContext . Response . Cache ;
2447- string [ ] values = value . Split ( ',' ) ;
2448- foreach ( string v in values )
2443+ switch ( v . Trim ( ) . ToUpper ( ) )
24492444 {
2450- switch ( v . Trim ( ) . ToUpper ( ) )
2451- {
2452- case "PUBLIC" :
2453- Cache . SetCacheability ( HttpCacheability . Public ) ;
2454- break ;
2455- case "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" ) ;
2463- break ;
2464- default :
2465- GXLogging . Warn ( log , String . Format ( "Could not set Cache Control Http Header Value '{0}' to HttpResponse" , value ) ) ;
2466- break ;
2467- }
2445+ case "PUBLIC" :
2446+ Cache . SetCacheability ( HttpCacheability . Public ) ;
2447+ break ;
2448+ case "PRIVATE" :
2449+ Cache . SetCacheability ( HttpCacheability . Private ) ;
2450+ break ;
2451+ case "NO-CACHE" :
2452+ Cache . SetCacheability ( HttpCacheability . NoCache ) ;
2453+ break ;
2454+ case "NO-STORE" :
2455+ Cache . AppendCacheExtension ( "no-store, must-revalidate" ) ;
2456+ break ;
2457+ default :
2458+ GXLogging . Warn ( log , String . Format ( "Could not set Cache Control Http Header Value '{0}' to HttpResponse" , value ) ) ;
2459+ break ;
24682460 }
24692461 }
24702462 }
24712463 else if ( name . Equals ( HeaderNames . ContentType , StringComparison . OrdinalIgnoreCase ) )
24722464 {
24732465 _HttpContext . Response . ContentType = value ;
24742466 }
2467+ else if ( name . Equals ( HeaderNames . Location , StringComparison . OrdinalIgnoreCase ) )
2468+ {
2469+ _HttpContext . Response . RedirectLocation = value ;
2470+ }
24752471 else
24762472 {
2477- if ( ! string . IsNullOrEmpty ( _HttpContext . Response . Headers [ name ] ) )
2473+ try
24782474 {
24792475 _HttpContext . Response . Headers [ name ] = value ;
2480- }
2481- else
2476+
2477+ } catch ( PlatformNotSupportedException ex )
24822478 {
24832479 _HttpContext . Response . AppendHeader ( name , value ) ;
2480+ GXLogging . Warn ( log , ex , "SetHeader " , name , value ) ;
24842481 }
24852482 }
24862483#else
@@ -2510,10 +2507,12 @@ private void SetCustomHttpHeader(string name, string value)
25102507 _HttpContext . Response . AddHeader ( name , value ) ;
25112508 }
25122509#endif
2510+ return 0 ;
25132511 }
25142512 catch ( Exception ex )
25152513 {
25162514 GXLogging . Error ( log , ex , "Error adding header " , name , value ) ;
2515+ return 1 ;
25172516 }
25182517 }
25192518
0 commit comments