Skip to content

Commit

Permalink
Clean code and required changes made
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattiav8 committed Jan 5, 2021
1 parent ba0e18c commit ed920b4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ strict-transport-security: max-age=31536000; includeSubDomains; preload

If Strict-Transport-Security is not enough to accomplish a forwarding connection to HTTPS from the browsers, you can opt to add an additional middleware who provides this redirection if clients try to reach your site with an HTTP connection.

To use the HSTS Redirect Middleware, you can add the following line in your middlewares, preferably before securityHeadersFactory.build():
To use the HTTPS Redirect Middleware, you can add the following line in **configure.swift** to enable the middleware. This must be done before `securityHeadersFactory.build()` to ensure HSTS works:

```swift
app.middleware.use(securityHeadersFactory.redirectMiddleware)
app.middleware.use(HTTPSRedirectMiddleware())
```

## Server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Vapor

public class HSTSRedirectMiddleware: Middleware {
public class HTTPSRedirectMiddleware: Middleware {

public init() {}

public func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response> {
if request.application.environment == .development {
return next.respond(to: request)
Expand Down
1 change: 0 additions & 1 deletion Sources/VaporSecurityHeaders/SecurityHeadersFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class SecurityHeadersFactory {
var server: ServerConfiguration?
var referrerPolicy: ReferrerPolicyConfiguration?
var contentSecurityPolicyReportOnly: ContentSecurityPolicyReportOnlyConfiguration?
public var redirectMiddleware = HSTSRedirectMiddleware()

public init() {}

Expand Down
2 changes: 1 addition & 1 deletion Tests/VaporSecurityHeadersTests/RedirectionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class RedirectionTest: XCTestCase {
application.environment = environment
}
if withRedirection == true {
application.middleware.use(SecurityHeadersFactory().redirectMiddleware)
application.middleware.use(HTTPSRedirectMiddleware())
}
try routes(application)
return try application.responder.respond(to: request).wait()
Expand Down

0 comments on commit ed920b4

Please sign in to comment.