Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
89783ac0
Commit
89783ac0
authored
Jan 29, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved extensionless middleware into its own package
parent
fe62afd3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
+18
-14
middleware/extensionless/extensionless.go
middleware/extensionless/extensionless.go
+18
-14
No files found.
middleware/extensionless.go
→
middleware/extensionless
/extensionless
.go
View file @
89783ac0
package
middleware
// Extensionless is middleware for clean URLs. A root path is
// passed in as well as possible extensions to add, internally,
// to paths requested. The first path+ext that matches a resource
// that exists will be used.
package
extensionless
import
(
"net/http"
"os"
"strings"
"github.com/mholt/caddy/middleware"
)
// Extensionless is middleware for clean URLs. A root path is
// passed in as well as possible extensions to add, internally,
// to paths requested. The first path+ext that matches a resource
// that exists will be used.
func
Extensionless
(
p
parser
)
Middleware
{
// New creates a new instance of middleware that assumes extensions
// so the site can use cleaner, extensionless URLs
func
New
(
c
middleware
.
Controller
)
(
middleware
.
Middleware
,
error
)
{
var
extensions
[]
string
var
root
=
p
.
Root
()
// TODO: Big gotcha! Save this now before it goes away! We can't get this later during a request!
var
root
=
c
.
Root
()
// TODO: Big gotcha! Save this now before it goes away! We can't get this later during a request!
for
p
.
Next
()
{
if
!
p
.
NextArg
()
{
return
p
.
ArgErr
()
for
c
.
Next
()
{
if
!
c
.
NextArg
()
{
return
nil
,
c
.
ArgErr
()
}
extensions
=
append
(
extensions
,
p
.
Val
())
for
p
.
NextArg
()
{
extensions
=
append
(
extensions
,
p
.
Val
())
extensions
=
append
(
extensions
,
c
.
Val
())
for
c
.
NextArg
()
{
extensions
=
append
(
extensions
,
c
.
Val
())
}
}
...
...
@@ -53,5 +57,5 @@ func Extensionless(p parser) Middleware {
}
next
(
w
,
r
)
}
}
}
,
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment