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

[Feature]: Cookies set in Set-Cookie header are now printed in cURLDescription() (along with any set in NSHTTPCookieStorage) #82

Closed
malcommac opened this issue Feb 17, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@malcommac
Copy link
Collaborator

malcommac commented Feb 17, 2023

What problem are you facing?

Actually, we'll deliberately ignore all cookies set with the Set-Cookie header when printing the cURL description via RealHTTP. It's annoying; sometimes, it's helpful to set cookies in this manner instead of creating an NSHTTPCookie object.

In this task, we'll remove the where condition when printing header cookies.

    private static func addHeaders(for request: URLRequest, whenIn client: HTTPClient, into components: inout [String]) {
        let configuration = client.session.configuration
        var headers = HTTPHeaders()
        
        for header in configuration.headers where header.name != "Cookie" {
            headers[header.name] = header.value
        }
        
        for header in request.headers where header.name != "Cookie" {
            headers[header.name] = header.value
        }
        
        for header in headers {
            let escapedValue = header.value.replacingOccurrences(of: "\"", with: "\\\"")
            components.append("-H \"\(header.name.rawValue): \(escapedValue)\"")
        }
    }

Other Information

No response

@malcommac malcommac added the enhancement New feature or request label Feb 17, 2023
@malcommac malcommac added this to the 1.8.2 milestone Feb 17, 2023
@malcommac malcommac self-assigned this Feb 17, 2023
malcommac added a commit that referenced this issue Feb 17, 2023
malcommac added a commit that referenced this issue Feb 17, 2023
@malcommac malcommac changed the title [Feature]: Print Cookie in cURLDescription() when cookies are set via explicit header [Feature]: Cookies set in Set-Cookie header are now printed in cURLDescription() (along with any set in NSHTTPCookieStorage) Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant