<commit_before>import HTTP
import URI

// MARK: Base

extension Responder {
    /// Creates a new client from the information in the
    /// Request URI and uses it to respond to the request.
    public func respond(
        to req: Request,
        through middleware: [Middleware] = []
    ) throws -> Response {
        return try middleware
            .chain(to: self)
            .respond(to: req)
    }
    
    /// Creates a new client and calls `.respond()`
    /// using the request method and uri provided.
    public func request(
        _ method: Method,
        _ uri: String,
        query: [String: NodeRepresentable] = [:],
        _ headers: [HeaderKey: String] = [:],
        _ body: BodyRepresentable? = nil,
        through middleware: [Middleware] = []
    ) throws  -> Response {
        let req = try makeRequest(method, uri, query: query, headers, body)
        return try respond(to: req, through: middleware)
    }

    /// for testing
    internal func makeRequest(
        _ method: Method,
        _ uri: String,
        query: [String: NodeRepresentable] = [:],
        _ headers: [HeaderKey: String] = [:],
        _ body: BodyRepresentable? = nil
    ) throws  -> Request {
        let uri = try URI(uri)

        let req = Request(method: method, uri: uri)
        req.headers = headers

        req.query = try Node(node: query)

        if let body = body {
            req.body = body.makeBody()
        }

        return req
    }<commit_msg>resolve query nil on uri pass client factory<commit_after>import HTTP
import URI

// MARK: Base

extension Responder {
    /// Creates a new client from the information in the
    /// Request URI and uses it to respond to the request.
    public func respond(
        to req: Request,
        through middleware: [Middleware] = []
    ) throws -> Response {
        return try middleware
            .chain(to: self)
            .respond(to: req)
    }
    
    /// Creates a new client and calls `.respond()`
    /// using the request method and uri provided.
    public func request(
        _ method: Method,
        _ uri: String,
        query: [String: NodeRepresentable] = [:],
        _ headers: [HeaderKey: String] = [:],
        _ body: BodyRepresentable? = nil,
        through middleware: [Middleware] = []
    ) throws  -> Response {
        let req = try makeRequest(method, uri, query: query, headers, body)
        return try respond(to: req, through: middleware)
    }

    /// for testing
    internal func makeRequest(
        _ method: Method,
        _ uri: String,
        query: [String: NodeRepresentable] = [:],
        _ headers: [HeaderKey: String] = [:],
        _ body: BodyRepresentable? = nil
    ) throws  -> Request {
        let uri = try URI(uri)

        let req = Request(method: method, uri: uri)
        req.headers = headers

        if !query.isEmpty {
            req.query = try Node(node: query)
        }

        if let body = body {
            req.body = body.makeBody()
        }

        return req
    }
{'fraction_non_alphanumeric': 0.10477759472817133, 'fraction_numerical': 0.0, 'mean_word_length': 1.8997134670487106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5930624', 'n_tokens_mistral': 851, 'n_tokens_neox': 829, 'n_words': 287}