From 56b540bfda031748efcec52c0a94840e5da00521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Wei=C3=9F?= Date: Thu, 19 Apr 2018 17:51:46 +0100 Subject: [PATCH] better descriptions for HTTP{Response,Request}Head and HTTPVersion (#339) Motivation: We recently changed the backing for the HTTP request and response objects so that the URI string was no longer visible in `request.description`. This patch fixes that and prints a format like this: HTTPRequestHead { method: GET, uri: "/", version: HTTP/1.1, headers: [("Host", "localhost:8888"), ("User-Agent", "curl/7.54.0"), ("Accept", "*/*")] } and HTTPResponseHead { version: HTTP/1.1, status: ok, headers: [("content-length", "12")] } Modifications: improved the HTTP request/response descriptions Result: debugging is easier --- Sources/NIOHTTP1/HTTPTypes.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sources/NIOHTTP1/HTTPTypes.swift b/Sources/NIOHTTP1/HTTPTypes.swift index e0b2e0238..310bd52d7 100644 --- a/Sources/NIOHTTP1/HTTPTypes.swift +++ b/Sources/NIOHTTP1/HTTPTypes.swift @@ -1372,3 +1372,21 @@ extension HTTPResponseStatus: Equatable { } } } + +extension HTTPRequestHead: CustomStringConvertible { + public var description: String { + return "HTTPRequestHead { method: \(self.method), uri: \"\(self.uri)\", version: \(self.version), headers: \(self.headers) }" + } +} + +extension HTTPResponseHead: CustomStringConvertible { + public var description: String { + return "HTTPResponseHead { version: \(self.version), status: \(self.status), headers: \(self.headers) }" + } +} + +extension HTTPVersion: CustomStringConvertible { + public var description: String { + return "HTTP/\(self.major).\(self.minor)" + } +}