Skip to content

Commit

Permalink
Merge pull request #91 from fortizpenaloza/fix-redirect
Browse files Browse the repository at this point in the history
Fix redirect to index file
  • Loading branch information
svenvc authored Apr 14, 2022
2 parents ce95eb0 + 745b1ff commit 9485e0f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ actualFilenameFor: uri
| subElements subDir entry |
(uri isEmpty and: [ self prefix isEmpty ]) ifTrue: [ ^ self indexFileIn: self directory ].
(self prefix isEmpty or: [ uri isEmpty not and: [ uri pathSegments beginsWith: self prefix ] ]) ifFalse: [ ^ nil ].
subElements := (uri pathSegments allButFirst: self prefix size) reject: [ :each | each = #/ ].
subElements := (uri pathSegments allButFirst: self prefix size) reject: [ :each | each = $/ ].
subDir := subElements allButLast inject: self directory into: [ :parent :sub | | file |
(file := parent / sub) exists
ifTrue: [ file ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
private
directoryRedirectFor: uri
| directoryUri |
directoryUri := uri copy addPathSegment: #/.
directoryUri := uri copy addPathSegment: $/.
^ ZnResponse redirect: directoryUri
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
private
indexHtml
^ '<html>
<head><title>Index</title></head>
<body><h1>Hi, i''m the index page</h1></body>
</html>
'
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ setUp
ZnFileSystemUtils
writeStreamFor: 'wide.html'
do: [ :stream |
stream nextPutAll: self wideHtml ].
stream nextPutAll: self wideHtml ].
ZnFileSystemUtils
writeStreamFor: 'index.html'
do: [ :stream |
stream nextPutAll: self indexHtml ].
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ tearDown
ZnFileSystemUtils
deleteIfExists: 'small.html';
deleteIfExists: 'large.html';
deleteIfExists: 'wide.html'.
deleteIfExists: 'wide.html';
deleteIfExists: 'index.html'.
super tearDown

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tests
testRedirect
self
withServerDo: [ :server |
| client |
(client := ZnClient new)
beOneShot;
url: server localUrl;
addPath: #('local-files');
get.
self assert: client isSuccess.
self assert: client response contentType equals: ZnMimeType textHtml.
self assert: client contents equals: self indexHtml.
self assert: (ZnUtils parseHttpDate: (client response headers at: 'Modification-Date')) equals: (ZnFileSystemUtils modificationTimeFor: 'index.html') asUTC.
self assert: (ZnUtils parseHttpDate: (client response headers at: 'Expires')) > (DateAndTime now + 10 days).
self assert: (client response headers at: 'Cache-Control') equals: (server delegate maxAgeFor: ZnMimeType textHtml) ]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "SvenVanCaekenberghe 12/8/2019 14:06",
"commentStamp" : "",
"super" : "TestCase",
"category" : "Zinc-HTTP-Examples",
"classinstvars" : [ ],
Expand Down

0 comments on commit 9485e0f

Please sign in to comment.