mutating func write()

in Sources/NIOHTTP1/HTTPEncoder.swift [208:465]


    mutating func write(response: HTTPResponseHead) {
        switch (response.version.major, response.version.minor, response.status) {
        // Optimization for HTTP/1.0
        case (1, 0, .custom(_, _)):
            self.writeStaticString("HTTP/1.0 ")
            self.write(status: response.status)
            self.writeStaticString("\r\n")
        case (1, 0, .continue):
            self.writeStaticString("HTTP/1.0 100 Continue\r\n")
        case (1, 0, .switchingProtocols):
            self.writeStaticString("HTTP/1.0 101 Switching Protocols\r\n")
        case (1, 0, .processing):
            self.writeStaticString("HTTP/1.0 102 Processing\r\n")
        case (1, 0, .ok):
            self.writeStaticString("HTTP/1.0 200 OK\r\n")
        case (1, 0, .created):
            self.writeStaticString("HTTP/1.0 201 Created\r\n")
        case (1, 0, .accepted):
            self.writeStaticString("HTTP/1.0 202 Accepted\r\n")
        case (1, 0, .nonAuthoritativeInformation):
            self.writeStaticString("HTTP/1.0 203 Non-Authoritative Information\r\n")
        case (1, 0, .noContent):
            self.writeStaticString("HTTP/1.0 204 No Content\r\n")
        case (1, 0, .resetContent):
            self.writeStaticString("HTTP/1.0 205 Reset Content\r\n")
        case (1, 0, .partialContent):
            self.writeStaticString("HTTP/1.0 206 Partial Content\r\n")
        case (1, 0, .multiStatus):
            self.writeStaticString("HTTP/1.0 207 Multi-Status\r\n")
        case (1, 0, .alreadyReported):
            self.writeStaticString("HTTP/1.0 208 Already Reported\r\n")
        case (1, 0, .imUsed):
            self.writeStaticString("HTTP/1.0 226 IM Used\r\n")
        case (1, 0, .multipleChoices):
            self.writeStaticString("HTTP/1.0 300 Multiple Choices\r\n")
        case (1, 0, .movedPermanently):
            self.writeStaticString("HTTP/1.0 301 Moved Permanently\r\n")
        case (1, 0, .found):
            self.writeStaticString("HTTP/1.0 302 Found\r\n")
        case (1, 0, .seeOther):
            self.writeStaticString("HTTP/1.0 303 See Other\r\n")
        case (1, 0, .notModified):
            self.writeStaticString("HTTP/1.0 304 Not Modified\r\n")
        case (1, 0, .useProxy):
            self.writeStaticString("HTTP/1.0 305 Use Proxy\r\n")
        case (1, 0, .temporaryRedirect):
            self.writeStaticString("HTTP/1.0 307 Tempory Redirect\r\n")
        case (1, 0, .permanentRedirect):
            self.writeStaticString("HTTP/1.0 308 Permanent Redirect\r\n")
        case (1, 0, .badRequest):
            self.writeStaticString("HTTP/1.0 400 Bad Request\r\n")
        case (1, 0, .unauthorized):
            self.writeStaticString("HTTP/1.0 401 Unauthorized\r\n")
        case (1, 0, .paymentRequired):
            self.writeStaticString("HTTP/1.0 402 Payment Required\r\n")
        case (1, 0, .forbidden):
            self.writeStaticString("HTTP/1.0 403 Forbidden\r\n")
        case (1, 0, .notFound):
            self.writeStaticString("HTTP/1.0 404 Not Found\r\n")
        case (1, 0, .methodNotAllowed):
            self.writeStaticString("HTTP/1.0 405 Method Not Allowed\r\n")
        case (1, 0, .notAcceptable):
            self.writeStaticString("HTTP/1.0 406 Not Acceptable\r\n")
        case (1, 0, .proxyAuthenticationRequired):
            self.writeStaticString("HTTP/1.0 407 Proxy Authentication Required\r\n")
        case (1, 0, .requestTimeout):
            self.writeStaticString("HTTP/1.0 408 Request Timeout\r\n")
        case (1, 0, .conflict):
            self.writeStaticString("HTTP/1.0 409 Conflict\r\n")
        case (1, 0, .gone):
            self.writeStaticString("HTTP/1.0 410 Gone\r\n")
        case (1, 0, .lengthRequired):
            self.writeStaticString("HTTP/1.0 411 Length Required\r\n")
        case (1, 0, .preconditionFailed):
            self.writeStaticString("HTTP/1.0 412 Precondition Failed\r\n")
        case (1, 0, .payloadTooLarge):
            self.writeStaticString("HTTP/1.0 413 Payload Too Large\r\n")
        case (1, 0, .uriTooLong):
            self.writeStaticString("HTTP/1.0 414 URI Too Long\r\n")
        case (1, 0, .unsupportedMediaType):
            self.writeStaticString("HTTP/1.0 415 Unsupported Media Type\r\n")
        case (1, 0, .rangeNotSatisfiable):
            self.writeStaticString("HTTP/1.0 416 Range Not Satisfiable\r\n")
        case (1, 0, .expectationFailed):
            self.writeStaticString("HTTP/1.0 417 Expectation Failed\r\n")
        case (1, 0, .misdirectedRequest):
            self.writeStaticString("HTTP/1.0 421 Misdirected Request\r\n")
        case (1, 0, .unprocessableEntity):
            self.writeStaticString("HTTP/1.0 422 Unprocessable Entity\r\n")
        case (1, 0, .locked):
            self.writeStaticString("HTTP/1.0 423 Locked\r\n")
        case (1, 0, .failedDependency):
            self.writeStaticString("HTTP/1.0 424 Failed Dependency\r\n")
        case (1, 0, .upgradeRequired):
            self.writeStaticString("HTTP/1.0 426 Upgrade Required\r\n")
        case (1, 0, .preconditionRequired):
            self.writeStaticString("HTTP/1.0 428 Precondition Required\r\n")
        case (1, 0, .tooManyRequests):
            self.writeStaticString("HTTP/1.0 429 Too Many Requests\r\n")
        case (1, 0, .requestHeaderFieldsTooLarge):
            self.writeStaticString("HTTP/1.0 431 Request Header Fields Too Large\r\n")
        case (1, 0, .unavailableForLegalReasons):
            self.writeStaticString("HTTP/1.0 451 Unavailable For Legal Reasons\r\n")
        case (1, 0, .internalServerError):
            self.writeStaticString("HTTP/1.0 500 Internal Server Error\r\n")
        case (1, 0, .notImplemented):
            self.writeStaticString("HTTP/1.0 501 Not Implemented\r\n")
        case (1, 0, .badGateway):
            self.writeStaticString("HTTP/1.0 502 Bad Gateway\r\n")
        case (1, 0, .serviceUnavailable):
            self.writeStaticString("HTTP/1.0 503 Service Unavailable\r\n")
        case (1, 0, .gatewayTimeout):
            self.writeStaticString("HTTP/1.0 504 Gateway Timeout\r\n")
        case (1, 0, .httpVersionNotSupported):
            self.writeStaticString("HTTP/1.0 505 HTTP Version Not Supported\r\n")
        case (1, 0, .variantAlsoNegotiates):
            self.writeStaticString("HTTP/1.0 506 Variant Also Negotiates\r\n")
        case (1, 0, .insufficientStorage):
            self.writeStaticString("HTTP/1.0 507 Insufficient Storage\r\n")
        case (1, 0, .loopDetected):
            self.writeStaticString("HTTP/1.0 508 Loop Detected\r\n")
        case (1, 0, .notExtended):
            self.writeStaticString("HTTP/1.0 510 Not Extended\r\n")
        case (1, 0, .networkAuthenticationRequired):
            self.writeStaticString("HTTP/1.1 511 Network Authentication Required\r\n")

        // Optimization for HTTP/1.1
        case (1, 1, .custom(_, _)):
            self.writeStaticString("HTTP/1.1 ")
            self.write(status: response.status)
            self.writeStaticString("\r\n")
        case (1, 1, .continue):
            self.writeStaticString("HTTP/1.1 100 Continue\r\n")
        case (1, 1, .switchingProtocols):
            self.writeStaticString("HTTP/1.1 101 Switching Protocols\r\n")
        case (1, 1, .processing):
            self.writeStaticString("HTTP/1.1 102 Processing\r\n")
        case (1, 1, .ok):
            self.writeStaticString("HTTP/1.1 200 OK\r\n")
        case (1, 1, .created):
            self.writeStaticString("HTTP/1.1 201 Created\r\n")
        case (1, 1, .accepted):
            self.writeStaticString("HTTP/1.1 202 Accepted\r\n")
        case (1, 1, .nonAuthoritativeInformation):
            self.writeStaticString("HTTP/1.1 203 Non-Authoritative Information\r\n")
        case (1, 1, .noContent):
            self.writeStaticString("HTTP/1.1 204 No Content\r\n")
        case (1, 1, .resetContent):
            self.writeStaticString("HTTP/1.1 205 Reset Content\r\n")
        case (1, 1, .partialContent):
            self.writeStaticString("HTTP/1.1 206 Partial Content\r\n")
        case (1, 1, .multiStatus):
            self.writeStaticString("HTTP/1.1 207 Multi-Status\r\n")
        case (1, 1, .alreadyReported):
            self.writeStaticString("HTTP/1.1 208 Already Reported\r\n")
        case (1, 1, .imUsed):
            self.writeStaticString("HTTP/1.1 226 IM Used\r\n")
        case (1, 1, .multipleChoices):
            self.writeStaticString("HTTP/1.1 300 Multiple Choices\r\n")
        case (1, 1, .movedPermanently):
            self.writeStaticString("HTTP/1.1 301 Moved Permanently\r\n")
        case (1, 1, .found):
            self.writeStaticString("HTTP/1.1 302 Found\r\n")
        case (1, 1, .seeOther):
            self.writeStaticString("HTTP/1.1 303 See Other\r\n")
        case (1, 1, .notModified):
            self.writeStaticString("HTTP/1.1 304 Not Modified\r\n")
        case (1, 1, .useProxy):
            self.writeStaticString("HTTP/1.1 305 Use Proxy\r\n")
        case (1, 1, .temporaryRedirect):
            self.writeStaticString("HTTP/1.1 307 Tempory Redirect\r\n")
        case (1, 1, .permanentRedirect):
            self.writeStaticString("HTTP/1.1 308 Permanent Redirect\r\n")
        case (1, 1, .badRequest):
            self.writeStaticString("HTTP/1.1 400 Bad Request\r\n")
        case (1, 1, .unauthorized):
            self.writeStaticString("HTTP/1.1 401 Unauthorized\r\n")
        case (1, 1, .paymentRequired):
            self.writeStaticString("HTTP/1.1 402 Payment Required\r\n")
        case (1, 1, .forbidden):
            self.writeStaticString("HTTP/1.1 403 Forbidden\r\n")
        case (1, 1, .notFound):
            self.writeStaticString("HTTP/1.1 404 Not Found\r\n")
        case (1, 1, .methodNotAllowed):
            self.writeStaticString("HTTP/1.1 405 Method Not Allowed\r\n")
        case (1, 1, .notAcceptable):
            self.writeStaticString("HTTP/1.1 406 Not Acceptable\r\n")
        case (1, 1, .proxyAuthenticationRequired):
            self.writeStaticString("HTTP/1.1 407 Proxy Authentication Required\r\n")
        case (1, 1, .requestTimeout):
            self.writeStaticString("HTTP/1.1 408 Request Timeout\r\n")
        case (1, 1, .conflict):
            self.writeStaticString("HTTP/1.1 409 Conflict\r\n")
        case (1, 1, .gone):
            self.writeStaticString("HTTP/1.1 410 Gone\r\n")
        case (1, 1, .lengthRequired):
            self.writeStaticString("HTTP/1.1 411 Length Required\r\n")
        case (1, 1, .preconditionFailed):
            self.writeStaticString("HTTP/1.1 412 Precondition Failed\r\n")
        case (1, 1, .payloadTooLarge):
            self.writeStaticString("HTTP/1.1 413 Payload Too Large\r\n")
        case (1, 1, .uriTooLong):
            self.writeStaticString("HTTP/1.1 414 URI Too Long\r\n")
        case (1, 1, .unsupportedMediaType):
            self.writeStaticString("HTTP/1.1 415 Unsupported Media Type\r\n")
        case (1, 1, .rangeNotSatisfiable):
            self.writeStaticString("HTTP/1.1 416 Request Range Not Satisified\r\n")
        case (1, 1, .expectationFailed):
            self.writeStaticString("HTTP/1.1 417 Expectation Failed\r\n")
        case (1, 1, .misdirectedRequest):
            self.writeStaticString("HTTP/1.1 421 Misdirected Request\r\n")
        case (1, 1, .unprocessableEntity):
            self.writeStaticString("HTTP/1.1 422 Unprocessable Entity\r\n")
        case (1, 1, .locked):
            self.writeStaticString("HTTP/1.1 423 Locked\r\n")
        case (1, 1, .failedDependency):
            self.writeStaticString("HTTP/1.1 424 Failed Dependency\r\n")
        case (1, 1, .upgradeRequired):
            self.writeStaticString("HTTP/1.1 426 Upgrade Required\r\n")
        case (1, 1, .preconditionRequired):
            self.writeStaticString("HTTP/1.1 428 Precondition Required\r\n")
        case (1, 1, .tooManyRequests):
            self.writeStaticString("HTTP/1.1 429 Too Many Requests\r\n")
        case (1, 1, .requestHeaderFieldsTooLarge):
            self.writeStaticString("HTTP/1.1 431 Range Not Satisfiable\r\n")
        case (1, 1, .unavailableForLegalReasons):
            self.writeStaticString("HTTP/1.1 451 Unavailable For Legal Reasons\r\n")
        case (1, 1, .internalServerError):
            self.writeStaticString("HTTP/1.1 500 Internal Server Error\r\n")
        case (1, 1, .notImplemented):
            self.writeStaticString("HTTP/1.1 501 Not Implemented\r\n")
        case (1, 1, .badGateway):
            self.writeStaticString("HTTP/1.1 502 Bad Gateway\r\n")
        case (1, 1, .serviceUnavailable):
            self.writeStaticString("HTTP/1.1 503 Service Unavailable\r\n")
        case (1, 1, .gatewayTimeout):
            self.writeStaticString("HTTP/1.1 504 Gateway Timeout\r\n")
        case (1, 1, .httpVersionNotSupported):
            self.writeStaticString("HTTP/1.1 505 HTTP Version Not Supported\r\n")
        case (1, 1, .variantAlsoNegotiates):
            self.writeStaticString("HTTP/1.1 506 Variant Also Negotiates\r\n")
        case (1, 1, .insufficientStorage):
            self.writeStaticString("HTTP/1.1 507 Insufficient Storage\r\n")
        case (1, 1, .loopDetected):
            self.writeStaticString("HTTP/1.1 508 Loop Detected\r\n")
        case (1, 1, .notExtended):
            self.writeStaticString("HTTP/1.1 510 Not Extended\r\n")
        case (1, 1, .networkAuthenticationRequired):
            self.writeStaticString("HTTP/1.1 511 Network Authentication Required\r\n")

        // Fallback for non-known HTTP version
        default:
            self.write(version: response.version)
            self.writeWhitespace()
            self.write(status: response.status)
            self.writeStaticString("\r\n")
        }
    }