Git Product home page Git Product logo

swift-charles-proxy's Introduction

Swift Charles Proxy

Instantiating

let agent = CharlesProxyAgent() // base url will be default : http://control.charles
let agent = CharlesProxyAgent(baseURL: "your own base url for charles web interface")

Basic Charles Control

Start Recording

let agent = CharlesProxyAgent()
agent.startRecord()

Stop Recording

let agent = CharlesProxyAgent()
agent.stopRecord()

Clear Session

let agent = CharlesProxyAgent()
agent.clearRecord()

Download Recording : Practical example

let agent = CharlesProxyAgent()
		agent.clearSession().then {
				let url = URL(string: "http://www.example.com")
				let mutableRequest = NSMutableURLRequest(url: url!)
				mutableRequest.addValue("world", forHTTPHeaderField: "hello")
				let task =  URLSession.shared.dataTask(with: mutableRequest as URLRequest, completionHandler: { (data, response, error) in
						agent.stopRecord().then {
							agent.downloadSession { session in
                let entries =  session?.filter(RequestHeaderFilter(header: ["hello":"world"]))
							}
						}
				})
				task.resume()
		}

Processing/Filtering Session

BaseURLFilter: Get session entries matching base url/s

If scheme e.g. https:// or http:// is not present, it will match scheme independent matching

let agent = CharlesProxyAgent()
agent.downloadSession { session in
  let entries = session?.filter(BaseURLFilter(urls: ["www.example.com", "www.twitter.com", "https://www.google.com"]))
}

RequestHeaderFilter: Get session entries matching header

let agent = CharlesProxyAgent()
agent.downloadSession { session in
  let entries =  session?.filter(RequestHeaderFilter(header: ["hello":"world"])) // entries with request with this header value  
}

QueryFilter: Get session entries matching particular queries

let agent = CharlesProxyAgent()
agent.downloadSession { session in
  let entries = session?.filter(QueryFilter(query: ["hello":"world"]))
}

ResponseHeaderFilter: Get session entries matching particular queries

let agent = CharlesProxyAgent()
agent.downloadSession { session in
  let entries = session?.filter(ResponseHeaderFilter(header: ["Vary":"Accept-Encoding"]))
}

Create Your Own Entry Filter

// implement EntryFilter protocol
public struct MyFilter: EntryFilter {
public func matches(_ entry: Entry) -> Bool {
  if(/*do something with entry*/ true)
		return true
	}
  return false
}

swift-charles-proxy's People

Stargazers

Dima Shmidt avatar

Watchers

James Cloos avatar Shaikh Sonny Aman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.