Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicated nil checks from DefaultResponder #2570

Merged
merged 2 commits into from Feb 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions Sources/Vapor/Responder/DefaultResponder.swift
Expand Up @@ -83,22 +83,19 @@ internal struct DefaultResponder: Responder {
statusCode: UInt
) {
let pathForMetrics: String
let methodForMetrics: String
if let route = request.route {
// We don't use route.description here to avoid duplicating the method in the path
pathForMetrics = "/\(route.path.map { "\($0)" }.joined(separator: "/"))"
methodForMetrics = request.method.string
} else {
// If the route is undefined (i.e. a 404 and not something like /users/:userID
// We rewrite the path and the method to undefined to avoid DOSing the
// application and any downstream metrics systems. Otherwise an attacker
// could spam the service with unlimited requests and exhaust the system
// with unlimited timers/counters
pathForMetrics = "vapor_route_undefined"
}
let methodForMetrics: String
if request.route == nil {
methodForMetrics = "undefined"
} else {
methodForMetrics = request.method.string
}
let dimensions = [
("method", methodForMetrics),
Expand Down