Skip to content

Commit 7eb97c1

Browse files
author
Marsel Tzatzo
authored
Merge pull request #165 from kasketis/feature/url_components
Add view controller for viewing query string params (if any) upon cli…
2 parents 8899692 + e7e4846 commit 7eb97c1

File tree

6 files changed

+119
-15
lines changed

6 files changed

+119
-15
lines changed

netfox.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

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

8788
/* Begin PBXFileReference section */
8889
026274D8214C6BC400AE1BDF /* WKWebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WKWebViewController.swift; sourceTree = "<group>"; };
90+
3708AD5922D4A9DD0050DB7D /* NFXURLDetailsControllerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NFXURLDetailsControllerViewController.swift; sourceTree = "<group>"; };
8991
8201A39C204E3E3F00AB2C3D /* NFXAuthenticationChallengeSender.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFXAuthenticationChallengeSender.swift; sourceTree = "<group>"; };
9092
8229AD621F8FB34300A9D613 /* netfox_ios_demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = netfox_ios_demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
9193
8229AD641F8FB34300A9D613 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -235,6 +237,7 @@
235237
B3F8BAA41C833AC700F9FBEA /* iOS */ = {
236238
isa = PBXGroup;
237239
children = (
240+
3708AD5922D4A9DD0050DB7D /* NFXURLDetailsControllerViewController.swift */,
238241
B3F8BAA51C833AC700F9FBEA /* NFXDetailsController_iOS.swift */,
239242
B3F8BAA61C833AC700F9FBEA /* NFXHelper_iOS.swift */,
240243
B3F8BAA71C833AC700F9FBEA /* NFXInfoController_iOS.swift */,
@@ -448,6 +451,7 @@
448451
B3F8BAA01C833ABC00F9FBEA /* NFXStatisticsController.swift in Sources */,
449452
B3F8BAB11C833AC700F9FBEA /* NFXSettingsController_iOS.swift in Sources */,
450453
B3F8BAB01C833AC700F9FBEA /* NFXListController_iOS.swift in Sources */,
454+
3708AD5A22D4A9DD0050DB7D /* NFXURLDetailsControllerViewController.swift in Sources */,
451455
B3F8BA8E1C833ABC00F9FBEA /* NFXHelper.swift in Sources */,
452456
B3F8BA861C833ABC00F9FBEA /* NFXConstants.swift in Sources */,
453457
B3F8BAAD1C833AC700F9FBEA /* NFXHelper_iOS.swift in Sources */,

netfox/Core/NFXGenericController.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class NFXGenericController: NFXViewController
5353

5454
for match in matchesKeys {
5555
tempMutableString.addAttribute(.foregroundColor, value: NFXColor.NFXBlackColor(), range: match.range)
56+
tempMutableString.addAttribute(.link,
57+
value: (string as NSString).substring(with: match.range),
58+
range: match.range)
5659
}
5760

5861
return tempMutableString

netfox/Core/NFXHTTPModel.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
2121
@objc public class NFXHTTPModel: NSObject
2222
{
2323
@objc public var requestURL: String?
24+
@objc public var requestURLComponents: URLComponents?
25+
@objc public var requestURLQueryItems: [URLQueryItem]?
2426
@objc public var requestMethod: String?
2527
@objc public var requestCachePolicy: String?
2628
@objc public var requestDate: Date?
@@ -46,11 +48,15 @@ fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
4648

4749
@objc public var noResponse: Bool = true
4850

51+
52+
4953
func saveRequest(_ request: URLRequest)
5054
{
5155
self.requestDate = Date()
5256
self.requestTime = getTimeFromDate(self.requestDate!)
5357
self.requestURL = request.getNFXURL()
58+
self.requestURLComponents = request.getNFXURLComponents()
59+
self.requestURLQueryItems = request.getNFXURLComponents()?.queryItems
5460
self.requestMethod = request.getNFXMethod()
5561
self.requestCachePolicy = request.getNFXCachePolicy()
5662
self.requestTimeout = request.getNFXTimeout()

netfox/Core/NFXHelper.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ extension URLRequest
132132
}
133133
}
134134

135+
func getNFXURLComponents() -> URLComponents?
136+
{
137+
guard let url = self.url else {
138+
return nil
139+
}
140+
return URLComponents(string: url.absoluteString)
141+
}
142+
135143
func getNFXMethod() -> String
136144
{
137145
if (httpMethod != nil) {

netfox/iOS/NFXDetailsController_iOS.swift

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,38 +134,40 @@ class NFXDetailsController_iOS: NFXDetailsController, MFMailComposeViewControlle
134134
scrollView.autoresizesSubviews = true
135135
scrollView.backgroundColor = UIColor.clear
136136

137-
var textLabel: UILabel
138-
textLabel = UILabel()
139-
textLabel.frame = CGRect(x: 20, y: 20, width: scrollView.frame.width - 40, height: scrollView.frame.height - 20);
140-
textLabel.font = UIFont.NFXFont(size: 13)
141-
textLabel.textColor = UIColor.NFXGray44Color()
142-
textLabel.numberOfLines = 0
143-
textLabel.attributedText = content
144-
textLabel.sizeToFit()
145-
textLabel.isUserInteractionEnabled = true
146-
scrollView.addSubview(textLabel)
137+
var textView: UITextView
138+
textView = UITextView()
139+
textView.frame = CGRect(x: 20, y: 20, width: scrollView.frame.width - 40, height: scrollView.frame.height - 20);
140+
textView.backgroundColor = UIColor.clear
141+
textView.font = UIFont.NFXFont(size: 13)
142+
textView.textColor = UIColor.NFXGray44Color()
143+
textView.isEditable = false
144+
textView.attributedText = content
145+
textView.sizeToFit()
146+
textView.isUserInteractionEnabled = true
147+
textView.delegate = self
148+
scrollView.addSubview(textView)
147149

148150
let lpgr = UILongPressGestureRecognizer(target: self, action: #selector(NFXDetailsController_iOS.copyLabel))
149-
textLabel.addGestureRecognizer(lpgr)
151+
textView.addGestureRecognizer(lpgr)
150152

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

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

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

167169
} else {
168-
scrollView.contentSize = CGSize(width: textLabel.frame.width, height: textLabel.frame.maxY + 16)
170+
scrollView.contentSize = CGSize(width: textView.frame.width, height: textView.frame.maxY + 16)
169171
}
170172

171173
return scrollView
@@ -336,4 +338,25 @@ extension NFXDetailsController_iOS: UIActivityItemSource {
336338
}
337339
}
338340

341+
extension NFXDetailsController_iOS: UITextViewDelegate {
342+
343+
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
344+
let decodedURL = URL.absoluteString.removingPercentEncoding
345+
switch decodedURL {
346+
case "[URL]":
347+
guard let queryItems = self.selectedModel.requestURLQueryItems, queryItems.count > 0 else {
348+
return false
349+
}
350+
let urlDetailsController = NFXURLDetailsController()
351+
urlDetailsController.selectedModel = self.selectedModel
352+
self.navigationController?.pushViewController(urlDetailsController, animated: true)
353+
return true
354+
default:
355+
return false
356+
}
357+
358+
}
359+
360+
}
361+
339362
#endif
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// NFXURLDetailsController.swift
3+
// netfox_ios
4+
//
5+
// Created by Tzatzo, Marsel on 05/06/2019.
6+
// Copyright © 2019 kasketis. All rights reserved.
7+
//
8+
9+
#if os(iOS)
10+
11+
import Foundation
12+
import UIKit
13+
14+
class NFXURLDetailsController: NFXDetailsController {
15+
16+
override func viewDidLoad() {
17+
super.viewDidLoad()
18+
self.title = "URL Query Strings"
19+
self.view.layer.masksToBounds = true
20+
self.view.translatesAutoresizingMaskIntoConstraints = true
21+
22+
let tableView: UITableView = UITableView()
23+
tableView.frame = self.view.bounds
24+
tableView.dataSource = self
25+
tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
26+
self.view.addSubview(tableView)
27+
}
28+
29+
}
30+
31+
extension NFXURLDetailsController: UITableViewDataSource {
32+
33+
func numberOfSections(in tableView: UITableView) -> Int {
34+
return 1
35+
}
36+
37+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
38+
var cell: UITableViewCell!
39+
cell = tableView.dequeueReusableCell(withIdentifier: "cell")
40+
if cell == nil {
41+
cell = UITableViewCell(style: .value1, reuseIdentifier: "cell")
42+
}
43+
if let queryItem = self.selectedModel.requestURLQueryItems?[indexPath.row] {
44+
cell.textLabel?.text = queryItem.name
45+
cell.detailTextLabel?.text = queryItem.value
46+
}
47+
return cell
48+
}
49+
50+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
51+
guard let queryItems = self.selectedModel.requestURLQueryItems else {
52+
return 0
53+
}
54+
return queryItems.count
55+
}
56+
57+
}
58+
59+
60+
#endif

0 commit comments

Comments
 (0)