iOS Network monitor/interceptor framework written in Swift

Related tags

Networking NetShears
Overview

Logo

NetShears

NetShears is a Network interceptor framework written in Swift.

NetShears adds a Request interceptor mechanisms to be able to modify the HTTP/HTTPS Request before being sent . This mechanism can be used to implement authentication policies, add headers to a request , add log trace or even redirect requests.

Features

  • Intercept HTTP/HTTPS request header
  • Intercept HTTP/HTTPS request endpoint
  • View traffic logs
  • Intercept HTTP/HTTPS response body
  • Block HTTP requets

How it works

NetShears working by swizzling the URLProtocol.

How to use

Start NetShears by calling startRecording() in didFinishLaunchingWithOptions

import NetShears

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {

	NetShears.startRecording()

}

Interceptor

Header Modification:

let header = HeaderModifyModel(key: "API-Version", value: "123")
let headerModifier = RequestEvaluatorModifierHeader(header: header)
NetShears.shared.modify(modifier: headerModifier)

Endpoint Modification:

let endpoint = RedirectedRequestModel(originalUrl: "/register", redirectUrl: "/login")
let endpointModifier = RequestEvaluatorModifierEndpoint(redirectedRequest: endpoint)
NetShears.shared.modify(modifier: endpointModifier)

Traffic Monitoring

In order to show network traffics in your app simply call presentNetworkMonitor method and then a view will present containing traffic logs.

NetShears.shared.presentNetworkMonitor()

Icon

gRPC

You can view gRPC calls by constructing the Request and Response from GRPC models:

public func addGRPC(url: String,
                        host: String,
                        requestObject: Data?,
                        responseObject: Data?,
                        success: Bool,
                        statusCode: Int,
                        statusMessage: String?,
                        duration: Double?,
                        HPACKHeadersRequest: [String: String]?,
                        HPACKHeadersResponse: [String: String]?)

Example

// Your GRPC services that is generated from SwiftGRPC
private let client = NoteServiceServiceClient.init(address: "127.0.0.1:12345", secure: false)


func insertNote(note: Note, completion: @escaping(Note?, CallResult?) -> Void) {
    _ = try? client.insert(note, completion: { (createdNote, result) in
    
        // Add to atlantis and show it on Proxyman app
        NetShears.shared.addGRPC(url: "https://test.com/grpc",
                         requestObject: try? note.jsonUTF8Data(),
                         responseObject: try? createdNote.jsonUTF8Data(),
                         success: result.success,
                         statusCode: result.statusCode.rawValue,
                         statusMessage: result.statusMessage)
    })
}

Installation

Swift Package Manager

Create a Package.swift file.

// swift-tools-version:5.0

import PackageDescription

let package = Package(
  name: "YourProject",
  dependencies: [
    .package(url: "https://github.com/divar-ir/NetShears.git", from: "1.0.0"),
  ],
  targets: [
    .target(name: "YourProject", dependencies: ["NetShears"])
  ]
)
$ swift build

CocoaPods

# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
    pod 'NetShears'
end

Replace YOUR_TARGET_NAME and then, in the Podfile directory, type:

$ pod install

Contributing

Please see our Contributing Guide.

Inspiration

License

MIT

Comments
  •  Add response online validator:

    Add response online validator:

    * view in online json validator/formmater added
    
    * response and toolbar in rtl languages issue fixed
    
    * body aligment in search mode fixed
    
    * body issue on dark mode fixed
    
    opened by aarashgoodarzi 2
  • NetShears dependancy with pod : Type 'Bundle' has no member 'module'

    NetShears dependancy with pod : Type 'Bundle' has no member 'module'

    Hello, I try to integrate your library into existing project, with pod dependancy.

    pod 'NetShears', :git => 'https://github.com/divar-ir/NetShears.git', :tag => '2.0.3'

    When i compile my project with your pod, I have an erreur during build :

    `XXX/Pods/NetShears/Sources/NetShears/UI/RequestDetailViewController.swift:45:79: error: type 'Bundle' has no member 'module' tableView.register(UINib(nibName: "TextTableViewCell", bundle: Bundle.module), forCellReuseIdentifier: "TextTableViewCell") ~~~~~~ ^~~~~~ XXX/Pods/NetShears/Sources/NetShears/UI/RequestDetailViewController.swift:46:85: error: type 'Bundle' has no member 'module' tableView.register(UINib(nibName: "ActionableTableViewCell", bundle: Bundle.module), forCellReuseIdentifier: "ActionableTableViewCell") ~~~~~~ ^~~~~~ XXX/Pods/NetShears/Sources/NetShears/UI/RequestDetailViewController.swift:47:85: error: type 'Bundle' has no member 'module' tableView.register(UINib(nibName: "RequestTitleSectionView", bundle: Bundle.module), forHeaderFooterViewReuseIdentifier: "RequestTitleSectionView") ~~~~~~ ^~~~~~

    Showing Recent Errors Only /Pods/NetShears/Sources/NetShears/UI/RequestDetailViewController.swift:45:79: Type 'Bundle' has no member 'module'`

    It seems your library it only compatible with Swift Package Manager, not with Cocoapods ?

    I work with Xcode 13.4.1.

    Thanks for your help.

    bug 
    opened by tonicfx 2
  • Intercept response body

    Intercept response body

    In some cases, we need to intercept the response body and act as a mock server. It can bed beneficial when working in a team, especially when some server APIs are not ready yet.

    It can start only by considering JSON formats, right now.

    help wanted approved idea 
    opened by mehdiimrz 2
  • Monitor netwrok traffic

    Monitor netwrok traffic

    It could be painful to intercept requests without monitoring network traffics. I can use some other third parties to monitor traffic, but since NetSheares swizzle URLProtocol it would take low effort to implement network traffic logs.

    help wanted work in progress approved idea 
    opened by mehdiimrz 1
  • Modify HTTP response

    Modify HTTP response

    This merge request adds response modification ability and RequestActionModifier protocol, which helps us with the implementation of some features like blocking requests in the future.

    enhancement review accepted 
    opened by pouyayarandi 0
  • Request filtering missing.

    Request filtering missing.

    As far as I understand the "ignore" feature only works for the viewer.

    I was expecting to be able to configure one interceptor, so that I can send custom headers to "MY SERVER", and not to every outgoing request. Our app uses multiple apis and it wont be convenient to share our headers with them ^^. Hopefully NetShears add this functionality.

    help wanted approved idea 
    opened by rcfrias 1
  • Implement User Interface for using modifiers

    Implement User Interface for using modifiers

    Right now, NetShears only provide API for interception. It would be nice if would be better if it also provides a user-friendly UI. It could be convenient for the quality assurance team for testing purposes.

    Public API could be something like this:

    Netshears.shared.showPanel()
    
    help wanted approved idea 
    opened by mehdiimrz 0
Releases(3.4.1)
  • 3.4.1(Nov 13, 2022)

    What's Changed

    • Fix missing request body by @mehdiimrz in https://github.com/divar-ir/NetShears/pull/25

    Full Changelog: https://github.com/divar-ir/NetShears/compare/3.4.0...3.4.1

    Source code(tar.gz)
    Source code(zip)
  • 3.4.0(Oct 2, 2022)

    What's Changed

    • Add response online validator by @aarashgoodarzi in https://github.com/divar-ir/NetShears/pull/23

    Full Changelog: https://github.com/divar-ir/NetShears/compare/3.3.0...3.4.0

    Source code(tar.gz)
    Source code(zip)
  • 3.3.0(Aug 10, 2022)

    What's Changed

    • Ignore request by @aarashgoodarzi in https://github.com/divar-ir/NetShears/pull/18

    New Contributors

    • @aarashgoodarzi made their first contribution in https://github.com/divar-ir/NetShears/pull/18

    Full Changelog: https://github.com/divar-ir/NetShears/compare/3.2.3...3.3.0

    Source code(tar.gz)
    Source code(zip)
  • 3.2.3(Jul 11, 2022)

  • 3.2.1(Jul 11, 2022)

    What's Changed

    • Fix pod dependency by @mehdiimrz in https://github.com/divar-ir/NetShears/pull/20

    Full Changelog: https://github.com/divar-ir/NetShears/compare/3.2.0...3.2.1

    Source code(tar.gz)
    Source code(zip)
  • 3.2.0(Jun 11, 2022)

    What's Changed

    • Fix typo in readme by @max-ott in https://github.com/divar-ir/NetShears/pull/16
    • Custom body export by @pouyayarandi in https://github.com/divar-ir/NetShears/pull/17

    New Contributors

    • @max-ott made their first contribution in https://github.com/divar-ir/NetShears/pull/16

    Full Changelog: https://github.com/divar-ir/NetShears/compare/3.1.0...3.2.0

    Source code(tar.gz)
    Source code(zip)
  • 3.1.0(Mar 5, 2022)

    What's Changed

    • Modify HTTP response by @pouyayarandi in https://github.com/divar-ir/NetShears/pull/15

    New Contributors

    • @pouyayarandi made their first contribution in https://github.com/divar-ir/NetShears/pull/15

    Full Changelog: https://github.com/divar-ir/NetShears/compare/3.0.2...3.1.0

    Source code(tar.gz)
    Source code(zip)
  • 3.0.2(Jan 16, 2022)

  • 3.0.1(Jan 10, 2022)

    What's Changed

    • set isFinished true for gRPC requests by @ialimz in https://github.com/divar-ir/NetShears/pull/10

    Full Changelog: https://github.com/divar-ir/NetShears/compare/3.0.0...3.0.1

    Source code(tar.gz)
    Source code(zip)
  • 3.0.0(Jan 9, 2022)

    What's Changed

    • Split recording to logger, interceptor and listener by @mehdiimrz in https://github.com/divar-ir/NetShears/pull/9

    Full Changelog: https://github.com/divar-ir/NetShears/compare/v2.0.5...3.0.0

    Source code(tar.gz)
    Source code(zip)
  • v2.0.5(Dec 13, 2021)

  • v2.0.4(Nov 28, 2021)

  • 2.0.3(Sep 28, 2021)

  • 2.0.1(Jul 12, 2021)

  • 2.0.0(Jul 12, 2021)

Owner
Divar
Divar
NWReachability - a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.

NWReachability is a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.

null 4 Dec 2, 2022
Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application.

Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application. Install Carthage

Ronan Rodrigo Nunes 89 Dec 26, 2022
A network extension app to block a user input URI. Meant as a network extension filter proof of concept.

URIBlockNE A network extension app to block a user input URI. Meant as a network extension filter proof of concept. This is just a research effort to

Charles Edge 5 Oct 17, 2022
Say goodbye to the Fat ugly singleton Network Manager with this Network Layer

MHNetwork Protocol Oriented Network Layer Aim to avoid having bloated singleton NetworkManager Philosophy the main philosophy behind MHNetwork is to h

Mohamed Emad Hegab 19 Nov 19, 2022
Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Igor 2 Sep 16, 2022
Baby Monitor iOS

Baby Monitor iOS Welcome to the Baby Monitor project. It's an application made for monitoring babies, which can help parents take care of their childr

Netguru 15 Sep 25, 2022
Network abstraction layer written in Swift.

Moya 14.0.0 A Chinese version of this document can be found here. You're a smart developer. You probably use Alamofire to abstract away access to URLS

Moya 14.4k Jan 1, 2023
A generic network layer written in swift

SwiftyNet 1.0.0 A generic network layer written in swift. you can use it as an abstraction layer above Alamofire with generic returned types. Installa

Mohamed Salah Zidane 17 Oct 11, 2021
A new, clean and lean network interface reachability library written in Swift.

Reachability A new, clean and lean network interface reachability library written in Swift. Remarks Network reachability changes can be monitored usin

Alecrim 7 Aug 8, 2022
Network abstraction layer written in Swift.

Moya 15.0.0 A Chinese version of this document can be found here. You're a smart developer. You probably use Alamofire to abstract away access to URLS

Moya 14.4k Jan 4, 2023
Alamofire Network Layer written in swift 5 using the protocol oriented, combine, UIKit, MVVM.

CoreAPI-iOS This project Contains Alamofire Network layer Based on Protocol Oriented Concept and Combine Framework. It is created with UIKit, Alamofir

Mehran Kamalifard 27 Nov 11, 2022
SwiftyReachability is a simple and lightweight network interface manager written in Swift.

SwiftyReachability is a simple and lightweight network interface manager written in Swift. Freely inspired by https://github.com/tonymillion/Reachabil

Antonio Guerra 5 Nov 4, 2022
Swift Paging is a framework that helps you load and display pages of data from a larger dataset from local storage or over network.

Swift Paging is a framework that helps you load and display pages of data from a larger dataset from local storage or over network. This approach allows your app to use both network bandwidth and system resources more efficiently. It's built on top of Combine, allowing you to harness its full power, handle errors easily, etc.

Gordan Glavaš 12 Dec 9, 2022
Lightweight network abstraction layer, written on top of Alamofire

TRON is a lightweight network abstraction layer, built on top of Alamofire. It can be used to dramatically simplify interacting with RESTful JSON web-

MLSDev 528 Dec 26, 2022
A toolkit for Network Extension Framework

NEKit NEKit is deprecated. It should still work but I'm not intent on maintaining it anymore. It has many flaws and needs a revamp to be a high-qualit

zhuhaow 2.8k Jan 2, 2023
A lightweight, one line setup, iOS / OSX network debugging library! 🦊

Netfox provides a quick look on all executed network requests performed by your iOS or OSX app. It grabs all requests - of course yours, requests from

Christos Kasketis 3.4k Dec 28, 2022
iOS network debugging, like a wizard 🧙‍♂️

Start debugging iOS network calls like a wizard, without extra code! Wormholy makes debugging quick and reliable. What you can do: No code to write an

Paolo Musolino 2.1k Jan 8, 2023
Network Diagnosis for iOS

Network Diagnosis for iOS 中文 Summary Network Diagnosis Library,support Ping/TcpPing/Rtmp/TraceRoute/DNS/external IP/external DNS。 Install CocoaPods po

Qiniu Cloud 139 Dec 10, 2022
An iOS LAN Network Scanner library

MMLanScan MMLanScan is an open source project for iOS that helps you scan your network and shows the available devices and their MAC Address, hostname

Michael Mavris 459 Dec 11, 2022