Skip to content

Commit

Permalink
Merge pull request #8 from divar-ir/make-request-model-propoerties-pu…
Browse files Browse the repository at this point in the history
…blic

Make request properties public and add isFnished property
  • Loading branch information
Karosahafi authored Dec 13, 2021
2 parents 06351aa + bdf5450 commit c6b6d8d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
35 changes: 19 additions & 16 deletions Sources/NetShears/Models/RequestModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ import Foundation
import UIKit

public final class NetShearsRequestModel: Codable {
let id: String
let url: String
let host: String?
let port: Int?
let scheme: String?
let date: Date
let method: String
let headers: [String: String]
var credentials: [String : String]
var cookies: String?
var httpBody: Data?
var code: Int
var responseHeaders: [String: String]?
var dataResponse: Data?
var errorClientDescription: String?
var duration: Double?
public let id: String
public let url: String
public let host: String?
public let port: Int?
public let scheme: String?
public let date: Date
public let method: String
public let headers: [String: String]
public var credentials: [String : String]
public var cookies: String?
public var httpBody: Data?
public var code: Int
public var responseHeaders: [String: String]?
public var dataResponse: Data?
public var errorClientDescription: String?
public var duration: Double?
public var isFinished: Bool

init(request: NSURLRequest, session: URLSession?) {
id = UUID().uuidString
Expand All @@ -37,6 +38,7 @@ public final class NetShearsRequestModel: Codable {
var headers = request.allHTTPHeaderFields ?? [:]
httpBody = request.httpBody
code = 0
isFinished = false


// collect all HTTP Request headers except the "Cookie" header. Many request representations treat cookies with special parameters or structures. For cookie collection, refer to the bottom part of this method
Expand Down Expand Up @@ -112,6 +114,7 @@ public final class NetShearsRequestModel: Codable {
self.port = nil
self.duration = duration
self.credentials = [:]
self.isFinished = false
}

var curlRequest: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class NetworkLoggerUrlProtocol: URLProtocol {
if let startDate = currentRequest?.date{
currentRequest?.duration = fabs(startDate.timeIntervalSinceNow) * 1000 //Find elapsed time and convert to milliseconds
}
currentRequest?.isFinished = true

if let request = currentRequest {
requestObserver.newRequestArrived(request)
Expand Down

0 comments on commit c6b6d8d

Please sign in to comment.