@@ -51,10 +51,14 @@ public async Task CheckRedirectPath()
5151 Assert . Equal ( "http://example.com/foo" , response . Headers . Location . OriginalString ) ;
5252 }
5353
54- [ Fact ]
55- public async Task CheckRedirectToHttps ( )
54+ [ Theory ]
55+ [ InlineData ( StatusCodes . Status301MovedPermanently ) ]
56+ [ InlineData ( StatusCodes . Status302Found ) ]
57+ [ InlineData ( StatusCodes . Status307TemporaryRedirect ) ]
58+ [ InlineData ( StatusCodes . Status308PermanentRedirect ) ]
59+ public async Task CheckRedirectToHttps ( int statusCode )
5660 {
57- var options = new RewriteOptions ( ) . AddRedirectToHttps ( statusCode : StatusCodes . Status301MovedPermanently ) ;
61+ var options = new RewriteOptions ( ) . AddRedirectToHttps ( statusCode : statusCode ) ;
5862 var builder = new WebHostBuilder ( )
5963 . Configure ( app =>
6064 {
@@ -65,8 +69,44 @@ public async Task CheckRedirectToHttps()
6569 var response = await server . CreateClient ( ) . GetAsync ( new Uri ( "http://example.com" ) ) ;
6670
6771 Assert . Equal ( "https://example.com/" , response . Headers . Location . OriginalString ) ;
72+ Assert . Equal ( statusCode , ( int ) response . StatusCode ) ;
73+ }
74+
75+ [ Fact ]
76+ public async Task CheckPermanentRedirectToHttps ( )
77+ {
78+ var options = new RewriteOptions ( ) . AddRedirectToHttpsPermanent ( ) ;
79+ var builder = new WebHostBuilder ( )
80+ . Configure ( app =>
81+ {
82+ app . UseRewriter ( options ) ;
83+ } ) ;
84+ var server = new TestServer ( builder ) ;
85+
86+ var response = await server . CreateClient ( ) . GetAsync ( new Uri ( "http://example.com" ) ) ;
87+
88+ Assert . Equal ( "https://example.com/" , response . Headers . Location . OriginalString ) ;
89+ Assert . Equal ( StatusCodes . Status301MovedPermanently , ( int ) response . StatusCode ) ;
6890 }
6991
92+ [ Theory ]
93+ [ InlineData ( 25 , "https://example.com:25/" ) ]
94+ [ InlineData ( - 25 , "https://example.com/" ) ]
95+ public async Task CheckRedirectToHttpsWithSslPort ( int sslPort , string expected )
96+ {
97+ var options = new RewriteOptions ( ) . AddRedirectToHttps ( statusCode : StatusCodes . Status301MovedPermanently , sslPort : sslPort ) ;
98+ var builder = new WebHostBuilder ( )
99+ . Configure ( app =>
100+ {
101+ app . UseRewriter ( options ) ;
102+ } ) ;
103+ var server = new TestServer ( builder ) ;
104+
105+ var response = await server . CreateClient ( ) . GetAsync ( new Uri ( "http://example.com" ) ) ;
106+
107+ Assert . Equal ( expected , response . Headers . Location . OriginalString ) ;
108+ Assert . Equal ( StatusCodes . Status301MovedPermanently , ( int ) response . StatusCode ) ;
109+ }
70110
71111 [ Fact ]
72112 public async Task CheckIfEmptyStringRedirectCorrectly ( )
0 commit comments