예제 #1
0
        public static Entry Export(Session session, bool requestOnly = false)
        {
            var entry = new Entry();
            entry.startedDateTime = session.Timers.ClientBeginRequest.ToString("o");
            entry.request = GetRequest(session);
            if (!requestOnly)
            {
                entry.response = GetResponse(session);
            }

            entry.timings = GetTimings(session.Timers);
            entry.comment = session["ui-comments"];

            entry.time = GetTotalTime(entry.timings);

            if (
                !string.IsNullOrEmpty(session["ui-comments"])
                // <-- not sure if this is correct, maybe a typo or missing assignation in BasicFormats?
                && !session.isFlagSet(SessionFlags.SentToGateway))
            {
                entry.serverIPAddress = session.m_hostIP;
            }
            entry.connection = session.clientPort.ToString(CultureInfo.InvariantCulture);
            return entry;
        }
예제 #2
0
        public static Table BuildEntryTable(Entry entry)
        {
            var table = new Table();

            AddSimpleValues(entry, table);

            AddRequest(table, entry.request);
            AddResponse(table, entry.response);

            AddTimings(table, entry.timings, entry.time);

            return table;
        }
예제 #3
0
        public EntryCompareResult FindMatch(IEnumerable<Entry> potentialMatches, Entry entryToMatch)
        {
            Entry matchedEntry = null;

            foreach (Entry potentialMatch in potentialMatches)
            {
                if (!CompareMethod(potentialMatch, entryToMatch))
                {
                    continue;
                }


                if (!CompareHost(potentialMatch, entryToMatch))
                {
                    continue;
                }

                if (!ComparePath(potentialMatch, entryToMatch))
                {
                    continue;
                }

                if (!CompareQueryString(potentialMatch, entryToMatch))
                {
                    continue;
                }

                if (!CompareHeaders(potentialMatch.request.headers, entryToMatch.request.headers))
                {
                    continue;
                }

                if (!ComparePostData(potentialMatch, entryToMatch))
                {
                    continue;
                }

                matchedEntry = potentialMatch;
                break;
            }


            return new EntryCompareResult { Match = matchedEntry };
        }
예제 #4
0
 public virtual bool ComparePostData(Entry potentialMatch, Entry entryToMatch)
 {
     if (potentialMatch.request.postData == null && entryToMatch.request.postData == null)
     {
         return true;
     }
     if (potentialMatch.request.postData == null || entryToMatch.request.postData == null)
     {
         return false;
     }
     if (potentialMatch.request.postData.text != entryToMatch.request.postData.text)
     {
         return false;
     }
     if (potentialMatch.request.postData.mimeType != entryToMatch.request.postData.mimeType)
     {
         return false;
     }
     if (!CompareParams(potentialMatch.request.postData.@params, entryToMatch.request.postData.@params))
     {
         return false;
     }
     return true;
 }
예제 #5
0
        public Entry MatchEntry(string tapeId, Entry entryToMatch, IEntryComparer[] comparers = null)
        {
            lock (_lockObject)
            {
                Tape tape = Select(tapeId);

                // provide a default comparer
                if (comparers == null || comparers.Length == 0)
                {
                    comparers = new IEntryComparer[] {new DefaultEntryComparer()};
                }

                List<Entry> potentialMatches = tape.log.entries;
                return (
                           from entryComparer in comparers
                           select entryComparer.FindMatch(potentialMatches, entryToMatch)
                           into result
                           where result.Match != null
                           select result.Match)
                    .FirstOrDefault();
            }
        }
예제 #6
0
 public virtual bool ComparePath(Entry potentialMatch, Entry entryToMatch)
 {
     return
         String.Compare(potentialMatch.request.path, entryToMatch.request.path,
                        StringComparison.OrdinalIgnoreCase) == 0;
 }
예제 #7
0
 public virtual bool CompareMethod(Entry potentialMatch, Entry entryToMatch)
 {
     return potentialMatch.request.method == entryToMatch.request.method;
 }
예제 #8
0
 public virtual bool CompareQueryString(Entry potentialMatch, Entry entryToMatch)
 {
     return CompareQueryString(potentialMatch.request.queryString, entryToMatch.request.queryString);
 }
예제 #9
0
        public static Session Import(Entry entry)
        {
            DateTime now;
            Request htRequest = entry.request;
            byte[] arrRequest = GetRequestFromEntry(htRequest);
            Response htResponse = entry.response;
            byte[] arrResponse = GetResponseFromEntry(htResponse);

            if ((arrRequest == null) || (arrResponse == null))
            {
                throw new Exception("Failed to get session from entry");
            }

            const SessionFlags responseStreamed = SessionFlags.ResponseStreamed;
            var session = new Session(arrRequest, arrResponse, responseStreamed);
            int num = GetTotalSize(htResponse);
            if (num > 0)
            {
                session["X-TRANSFER-SIZE"] = num.ToString(CultureInfo.InvariantCulture);
            }

            session["ui-comments"] = entry.comment;

            if (!DateTime.TryParse(entry.startedDateTime, out now))
            {
                now = DateTime.Now;
            }

            session.Timers.DNSTime = entry.timings.dns;
            session.Timers.TCPConnectTime = entry.timings.connect;
            session.Timers.HTTPSHandshakeTime = entry.timings.ssl;
            session.Timers.ClientConnected = session.Timers.ClientBeginRequest = session.Timers.ClientDoneRequest = now;
            session.Timers.ServerConnected =
                session.Timers.FiddlerBeginRequest =
                now.AddMilliseconds(((entry.timings.blocked + session.Timers.DNSTime) + session.Timers.TCPConnectTime) +
                                    session.Timers.HTTPSHandshakeTime);
            session.Timers.ServerGotRequest = session.Timers.FiddlerBeginRequest.AddMilliseconds(entry.timings.send);
            session.Timers.ServerBeginResponse = now.AddMilliseconds(entry.timings.wait);
            session.Timers.ServerDoneResponse =
                session.Timers.ServerBeginResponse.AddMilliseconds(entry.timings.receive);
            session.Timers.ClientBeginResponse = session.Timers.ClientDoneResponse = session.Timers.ServerDoneResponse;
            return session;
        }
예제 #10
0
 private static void AddSimpleValues(Entry entry, Table table)
 {
     AddTextRow("startedDateTime", entry.startedDateTime, table);
     //AddTextRow("time", entry.time, table);
     //AddTextRow("comment", entry.comment, table);
     //AddTextRow("connection", entry.connection, table);
     //AddTextRow("pageref", entry.pageref, table);
     //AddTextRow("serverIPAddress", entry.serverIPAddress, table);
 }