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

Empty details when viewing a request body. #31

Open
dbreese opened this issue Aug 18, 2023 · 2 comments
Open

Empty details when viewing a request body. #31

dbreese opened this issue Aug 18, 2023 · 2 comments

Comments

@dbreese
Copy link

dbreese commented Aug 18, 2023

When attempting to view a request/response, the View Body for the Request Body is always blank, even though Content-Length is > 0.

Testing with 3.2.3 (and with latest from master)

@dbreese
Copy link
Author

dbreese commented Aug 21, 2023

This appears to be because NSUrlRequest.httpBody is nil, but httpBodyStream is what contains the data. Unfortunately, reading this stream consumes the body, so it looks like what needs to happen is for NetShears to copy the NSUrlRequest and recreate the request after reading the body.

@rickirby
Copy link

rickirby commented Feb 9, 2025

Hi @dbreese
I'm facing the same issue as you mentioned before.
For a short debugging, currently I find a workaround for this issue by modifying the URLSessionConfiguration+Extension.swift by following code.

extension URLSessionConfiguration {
    
    @objc func fakeProcotolClasses() -> [AnyClass]? {
        guard let fakeProcotolClasses = self.fakeProcotolClasses() else {
            return []
        }
        var originalProtocolClasses = fakeProcotolClasses.filter {
            return $0 != NetworkInterceptorUrlProtocol.self && $0 != NetworkLoggerUrlProtocol.self && $0 != NetwrokListenerUrlProtocol.self
        }
        
        if NetShears.shared.listenerEnable {
            originalProtocolClasses.insert(NetwrokListenerUrlProtocol.self, at: 0)
        }
        if NetShears.shared.loggerEnable {
            originalProtocolClasses.insert(NetworkLoggerUrlProtocol.self, at: 0)
        }
        if NetShears.shared.interceptorEnable {
            originalProtocolClasses.insert(NetworkInterceptorUrlProtocol.self, at: 0)
        }
        return originalProtocolClasses
    }
    
}

The idea is to switch the position of NetwrokListenerUrlProtocol and NetworkLoggerUrlProtocol and it works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants