https://github.com/grottopress/unslash
A Crystal HTTP Handler to remove trailing slashes from URLs
https://github.com/grottopress/unslash
crystal http-handler
Last synced: 2 months ago
JSON representation
A Crystal HTTP Handler to remove trailing slashes from URLs
- Host: GitHub
- URL: https://github.com/grottopress/unslash
- Owner: GrottoPress
- License: mit
- Created: 2021-12-18T15:48:01.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-08-23T12:38:24.000Z (over 1 year ago)
- Last Synced: 2025-01-27T14:49:05.955Z (4 months ago)
- Topics: crystal, http-handler
- Language: Crystal
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Unslash
**Unslash** is a *Crystal* HTTP handler that removes slashes (`/`) at the end of URLs, performing a redirect to the unslashed version of the same URL.
This, among others, improves SEO by avoiding duplicated content across the different versions of the same URL.
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
unslash:
github: GrottoPress/unslash
```1. Run `shards update`
1. Require *Unslash*:
```crystal
# ...
require "unslash"
# ...
```## Usage
Pass an instance of `Unslash::Handler` to the web server. If using a web framework, this handler should be passed before the framework's route handler:
```crystal
# ...
require "http/server"
require "unslash"server = HTTP::Server.new([
# If `safe` is `true`, only `GET` and `HEAD` request methods
# are handled.
Unslash::Handler.new(status_code: 308, safe: false),
# ...
])server.bind_tcp("127.0.0.1", 8080)
server.listen
# ...
```## Development
Run tests with `crystal spec`.
## Contributing
1. [Fork it](https://github.com/GrottoPress/unslash/fork)
1. Switch to the `master` branch: `git checkout master`
1. Create your feature branch: `git checkout -b my-new-feature`
1. Make your changes, updating changelog and documentation as appropriate.
1. Commit your changes: `git commit`
1. Push to the branch: `git push origin my-new-feature`
1. Submit a new *Pull Request* against the `GrottoPress:master` branch.