Skip to content

Commit

Permalink
Merge pull request #165 from kasketis/feature/url_components
Browse files Browse the repository at this point in the history
Add view controller for viewing query string params (if any) upon cli…
  • Loading branch information
Marsel Tzatzo authored Jul 22, 2019
2 parents 8899692 + e7e4846 commit 7eb97c1
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 15 deletions.
4 changes: 4 additions & 0 deletions netfox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
026274D9214C6BC400AE1BDF /* WKWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 026274D8214C6BC400AE1BDF /* WKWebViewController.swift */; };
3708AD5A22D4A9DD0050DB7D /* NFXURLDetailsControllerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3708AD5922D4A9DD0050DB7D /* NFXURLDetailsControllerViewController.swift */; };
8201A39D204E3E3F00AB2C3D /* NFXAuthenticationChallengeSender.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8201A39C204E3E3F00AB2C3D /* NFXAuthenticationChallengeSender.swift */; };
8201A39E204E451900AB2C3D /* NFXAuthenticationChallengeSender.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8201A39C204E3E3F00AB2C3D /* NFXAuthenticationChallengeSender.swift */; };
8201A39F204E452200AB2C3D /* NFXLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 826C4E9D1F979AB3008B440C /* NFXLoader.m */; };
Expand Down Expand Up @@ -86,6 +87,7 @@

/* Begin PBXFileReference section */
026274D8214C6BC400AE1BDF /* WKWebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WKWebViewController.swift; sourceTree = "<group>"; };
3708AD5922D4A9DD0050DB7D /* NFXURLDetailsControllerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NFXURLDetailsControllerViewController.swift; sourceTree = "<group>"; };
8201A39C204E3E3F00AB2C3D /* NFXAuthenticationChallengeSender.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFXAuthenticationChallengeSender.swift; sourceTree = "<group>"; };
8229AD621F8FB34300A9D613 /* netfox_ios_demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = netfox_ios_demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
8229AD641F8FB34300A9D613 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -235,6 +237,7 @@
B3F8BAA41C833AC700F9FBEA /* iOS */ = {
isa = PBXGroup;
children = (
3708AD5922D4A9DD0050DB7D /* NFXURLDetailsControllerViewController.swift */,
B3F8BAA51C833AC700F9FBEA /* NFXDetailsController_iOS.swift */,
B3F8BAA61C833AC700F9FBEA /* NFXHelper_iOS.swift */,
B3F8BAA71C833AC700F9FBEA /* NFXInfoController_iOS.swift */,
Expand Down Expand Up @@ -448,6 +451,7 @@
B3F8BAA01C833ABC00F9FBEA /* NFXStatisticsController.swift in Sources */,
B3F8BAB11C833AC700F9FBEA /* NFXSettingsController_iOS.swift in Sources */,
B3F8BAB01C833AC700F9FBEA /* NFXListController_iOS.swift in Sources */,
3708AD5A22D4A9DD0050DB7D /* NFXURLDetailsControllerViewController.swift in Sources */,
B3F8BA8E1C833ABC00F9FBEA /* NFXHelper.swift in Sources */,
B3F8BA861C833ABC00F9FBEA /* NFXConstants.swift in Sources */,
B3F8BAAD1C833AC700F9FBEA /* NFXHelper_iOS.swift in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions netfox/Core/NFXGenericController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class NFXGenericController: NFXViewController

for match in matchesKeys {
tempMutableString.addAttribute(.foregroundColor, value: NFXColor.NFXBlackColor(), range: match.range)
tempMutableString.addAttribute(.link,
value: (string as NSString).substring(with: match.range),
range: match.range)
}

return tempMutableString
Expand Down
6 changes: 6 additions & 0 deletions netfox/Core/NFXHTTPModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
@objc public class NFXHTTPModel: NSObject
{
@objc public var requestURL: String?
@objc public var requestURLComponents: URLComponents?
@objc public var requestURLQueryItems: [URLQueryItem]?
@objc public var requestMethod: String?
@objc public var requestCachePolicy: String?
@objc public var requestDate: Date?
Expand All @@ -46,11 +48,15 @@ fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {

@objc public var noResponse: Bool = true



func saveRequest(_ request: URLRequest)
{
self.requestDate = Date()
self.requestTime = getTimeFromDate(self.requestDate!)
self.requestURL = request.getNFXURL()
self.requestURLComponents = request.getNFXURLComponents()
self.requestURLQueryItems = request.getNFXURLComponents()?.queryItems
self.requestMethod = request.getNFXMethod()
self.requestCachePolicy = request.getNFXCachePolicy()
self.requestTimeout = request.getNFXTimeout()
Expand Down
8 changes: 8 additions & 0 deletions netfox/Core/NFXHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ extension URLRequest
}
}

func getNFXURLComponents() -> URLComponents?
{
guard let url = self.url else {
return nil
}
return URLComponents(string: url.absoluteString)
}

func getNFXMethod() -> String
{
if (httpMethod != nil) {
Expand Down
53 changes: 38 additions & 15 deletions netfox/iOS/NFXDetailsController_iOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,38 +134,40 @@ class NFXDetailsController_iOS: NFXDetailsController, MFMailComposeViewControlle
scrollView.autoresizesSubviews = true
scrollView.backgroundColor = UIColor.clear

var textLabel: UILabel
textLabel = UILabel()
textLabel.frame = CGRect(x: 20, y: 20, width: scrollView.frame.width - 40, height: scrollView.frame.height - 20);
textLabel.font = UIFont.NFXFont(size: 13)
textLabel.textColor = UIColor.NFXGray44Color()
textLabel.numberOfLines = 0
textLabel.attributedText = content
textLabel.sizeToFit()
textLabel.isUserInteractionEnabled = true
scrollView.addSubview(textLabel)
var textView: UITextView
textView = UITextView()
textView.frame = CGRect(x: 20, y: 20, width: scrollView.frame.width - 40, height: scrollView.frame.height - 20);
textView.backgroundColor = UIColor.clear
textView.font = UIFont.NFXFont(size: 13)
textView.textColor = UIColor.NFXGray44Color()
textView.isEditable = false
textView.attributedText = content
textView.sizeToFit()
textView.isUserInteractionEnabled = true
textView.delegate = self
scrollView.addSubview(textView)

let lpgr = UILongPressGestureRecognizer(target: self, action: #selector(NFXDetailsController_iOS.copyLabel))
textLabel.addGestureRecognizer(lpgr)
textView.addGestureRecognizer(lpgr)

var moreButton: UIButton
moreButton = UIButton.init(frame: CGRect(x: 20, y: textLabel.frame.maxY + 10, width: scrollView.frame.width - 40, height: 40))
moreButton = UIButton.init(frame: CGRect(x: 20, y: textView.frame.maxY + 10, width: scrollView.frame.width - 40, height: 40))
moreButton.backgroundColor = UIColor.NFXGray44Color()

if ((forView == EDetailsView.request) && (self.selectedModel.requestBodyLength > 1024)) {
moreButton.setTitle("Show request body", for: .init())
moreButton.addTarget(self, action: #selector(NFXDetailsController_iOS.requestBodyButtonPressed), for: .touchUpInside)
scrollView.addSubview(moreButton)
scrollView.contentSize = CGSize(width: textLabel.frame.width, height: moreButton.frame.maxY + 16)
scrollView.contentSize = CGSize(width: textView.frame.width, height: moreButton.frame.maxY + 16)

} else if ((forView == EDetailsView.response) && (self.selectedModel.responseBodyLength > 1024)) {
moreButton.setTitle("Show response body", for: .init())
moreButton.addTarget(self, action: #selector(NFXDetailsController_iOS.responseBodyButtonPressed), for: .touchUpInside)
scrollView.addSubview(moreButton)
scrollView.contentSize = CGSize(width: textLabel.frame.width, height: moreButton.frame.maxY + 16)
scrollView.contentSize = CGSize(width: textView.frame.width, height: moreButton.frame.maxY + 16)

} else {
scrollView.contentSize = CGSize(width: textLabel.frame.width, height: textLabel.frame.maxY + 16)
scrollView.contentSize = CGSize(width: textView.frame.width, height: textView.frame.maxY + 16)
}

return scrollView
Expand Down Expand Up @@ -336,4 +338,25 @@ extension NFXDetailsController_iOS: UIActivityItemSource {
}
}

extension NFXDetailsController_iOS: UITextViewDelegate {

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
let decodedURL = URL.absoluteString.removingPercentEncoding
switch decodedURL {
case "[URL]":
guard let queryItems = self.selectedModel.requestURLQueryItems, queryItems.count > 0 else {
return false
}
let urlDetailsController = NFXURLDetailsController()
urlDetailsController.selectedModel = self.selectedModel
self.navigationController?.pushViewController(urlDetailsController, animated: true)
return true
default:
return false
}

}

}

#endif
60 changes: 60 additions & 0 deletions netfox/iOS/NFXURLDetailsControllerViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// NFXURLDetailsController.swift
// netfox_ios
//
// Created by Tzatzo, Marsel on 05/06/2019.
// Copyright © 2019 kasketis. All rights reserved.
//

#if os(iOS)

import Foundation
import UIKit

class NFXURLDetailsController: NFXDetailsController {

override func viewDidLoad() {
super.viewDidLoad()
self.title = "URL Query Strings"
self.view.layer.masksToBounds = true
self.view.translatesAutoresizingMaskIntoConstraints = true

let tableView: UITableView = UITableView()
tableView.frame = self.view.bounds
tableView.dataSource = self
tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.view.addSubview(tableView)
}

}

extension NFXURLDetailsController: UITableViewDataSource {

func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell: UITableViewCell!
cell = tableView.dequeueReusableCell(withIdentifier: "cell")
if cell == nil {
cell = UITableViewCell(style: .value1, reuseIdentifier: "cell")
}
if let queryItem = self.selectedModel.requestURLQueryItems?[indexPath.row] {
cell.textLabel?.text = queryItem.name
cell.detailTextLabel?.text = queryItem.value
}
return cell
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let queryItems = self.selectedModel.requestURLQueryItems else {
return 0
}
return queryItems.count
}

}


#endif

0 comments on commit 7eb97c1

Please sign in to comment.