Repository: vapor/vapor
File: Sources/Vapor/Request/Request.swift (Swift)

Code before:
            version: version,
            headersNoUpdate: headers,
            collectedBody: collectedBody,
            remoteAddress: remoteAddress,
            logger: logger,
            byteBufferAllocator: byteBufferAllocator,
            on: eventLoop
        )
        if let body = collectedBody {
            self.headers.updateContentLength(body.readableBytes)
        }
    }
    
    public init(
        application: Application,
        method: HTTPMethod,
        url: URI,
        version: HTTPVersion = .init(major: 1, minor: 1),
        headersNoUpdate headers: HTTPHeaders = .init(),
        collectedBody: ByteBuffer? = nil,
        remoteAddress: SocketAddress? = nil,
        logger: Logger = .init(label: "codes.vapor.request"),
        byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(),
        on eventLoop: EventLoop
    ) {
        let requestId = headers[.xRequestId].first ?? UUID().uuidString
        let bodyStorage: BodyStorage
        if let body = collectedBody {
            bodyStorage = .collected(body)
        } else {
            bodyStorage = .none
        }
        
        var logger = logger
        logger[metadataKey: "request-id"] = .string(requestId)
        self._logger = .init(logger)
        
        let storageBox = RequestBox(
            method: method,
            url: url,
            version: version,
            headers: headers,
            isKeepAlive: true,
            route: nil,
            parameters: .init(),
            byteBufferAllocator: byteBufferAllocator
        )
        self.requestBox = .init(storageBox)
        self.id = requestId
        self.application = application
        

Review comment (suggestion):
Looks fine but i'd prefer `.first(name:)`, will be slightly more performant as it wouldn't be filter/collecting stuff when eventually we do `.first` anyway:
```suggestion
        let requestId = headers.first(name: .xRequestId) ?? UUID().uuidString
```

Code after:
            version: version,
            headersNoUpdate: headers,
            collectedBody: collectedBody,
            remoteAddress: remoteAddress,
            logger: logger,
            byteBufferAllocator: byteBufferAllocator,
            on: eventLoop
        )
        if let body = collectedBody {
            self.headers.updateContentLength(body.readableBytes)
        }
    }
    
    public init(
        application: Application,
        method: HTTPMethod,
        url: URI,
        version: HTTPVersion = .init(major: 1, minor: 1),
        headersNoUpdate headers: HTTPHeaders = .init(),
        collectedBody: ByteBuffer? = nil,
        remoteAddress: SocketAddress? = nil,
        logger: Logger = .init(label: "codes.vapor.request"),
        byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(),
        on eventLoop: EventLoop
    ) {
        let requestId = headers.first(name: .xRequestId) ?? UUID().uuidString
        let bodyStorage: BodyStorage
        if let body = collectedBody {
            bodyStorage = .collected(body)
        } else {
            bodyStorage = .none
        }
        
        var logger = logger
        logger[metadataKey: "request-id"] = .string(requestId)
        self._logger = .init(logger)
        
        let storageBox = RequestBox(
            method: method,
            url: url,
            version: version,
            headers: headers,
            isKeepAlive: true,
            route: nil,
            parameters: .init(),
            byteBufferAllocator: byteBufferAllocator
        )
        self.requestBox = .init(storageBox)
        self.id = requestId
        self.application = application