示例#1
0
        private void ProcessBeginRequest(Session oS)
        {
            var info = new SessionInfo(oS);

            oS.host = info.Host;
            oS.PathAndQuery = info.PathAndQuery;

            switch (info.Type)
            {
                case SessionType.Record:
                    RecordSession(oS, info);
                    break;

                case SessionType.Playback:
                    PlaybackSession(oS, info);
                    break;
                case SessionType.InvalidMimeType:
                    oS.utilCreateResponseAndBypassServer();
                    oS.responseCode = 500;
                    oS.utilSetResponseBody("Invalid MIME type");

                    break;
                case SessionType.Export:
                    oS.utilCreateResponseAndBypassServer();
                    oS.responseCode = 200;
                    // #TODO: set content-type etc
                    Tape tape = _store.Select(info.UserId + "." + info.TapeId);
                    if (tape == null)
                    {
                        oS.utilCreateResponseAndBypassServer();
                        oS.responseCode = 404;
                        oS.utilSetResponseBody("Tape not found");
                        return;
                    }
                    oS.oResponse.headers["Content-Type"] = "text/json";
                    oS.utilSetResponseBody(JsonConvert.SerializeObject(tape, Formatting.Indented));

                    break;

            }
        }
示例#2
0
 private void RecordSession(Session oS, SessionInfo info)
 {
     try
     {
         if (_secured)
         {
             Tape tape = _store.Select(info.UserId + "." + info.TapeId);
             if (tape == null)
             {
                 oS.utilCreateResponseAndBypassServer();
                 oS.responseCode = 404;
                 oS.utilSetResponseBody("Tape not found");
                 return;
             }
             if (!tape.OpenForRecording)
             {
                 oS.utilCreateResponseAndBypassServer();
                 oS.responseCode = 412;
                 oS.utilSetResponseBody("Tape is not open for recording");
                 return;
             }
             string ip = GetClientIp(oS);
             if (ip != tape.AllowedIpAddress)
             {
                 oS.utilCreateResponseAndBypassServer();
                 oS.responseCode = 403;
                 oS.utilSetResponseBody("IP " + GetClientIp(oS) + " not allowed to record.");
                 return;
             }
         }
         oS.bBufferResponse = true;
         RecordCache.TryAdd(oS, info);
     }
     catch
     {
         oS.utilCreateResponseAndBypassServer();
         oS.responseCode = 500;
         oS.utilSetResponseBody("Exception occurred");
     }
 }
示例#3
0
        private void PlaybackSession(Session oS, SessionInfo info)
        {
            try
            {
                string tapeId = info.UserId + "." + info.TapeId;
                Tape tape = _store.Select(tapeId);
                if (tape == null)
                {
                    oS.utilCreateResponseAndBypassServer();
                    oS.responseCode = 404;
                    oS.utilSetResponseBody("Tape not found");
                    return;
                }

                // time to find matching session
                Entry entry = HttpArchiveTranscoder.Export(oS, true);

                Entry matchedEntry = _store.MatchEntry(tapeId, entry);

                if (matchedEntry == null)
                {
                    oS.utilCreateResponseAndBypassServer();
                    oS.responseCode = 404;
                    oS.utilSetResponseBody("Matching entry not found");
                }
                else
                {
                    Session matchedSession = HttpArchiveTranscoder.Import(matchedEntry);
                    oS.utilCreateResponseAndBypassServer();
                    // #TODO: figger me out
                    // odd, fiddler is compressing respose when it is not compressed from server
                    //oS.responseBodyBytes = matchedSession.responseBodyBytes;

                    oS.utilSetResponseBody(matchedEntry.response.content.text);
                    oS.oResponse.headers = (HTTPResponseHeaders)matchedSession.oResponse.headers.Clone();

                    // #TODO: figger me out
                    oS.oResponse.headers["Content-Length"] = matchedEntry.response.content.text.Length.ToString();
                    // #TODO: figger me out
                    oS.oResponse.headers.Remove("Content-Encoding");
                }
            }
            catch
            {
                oS.utilCreateResponseAndBypassServer();
                oS.responseCode = 500;
                oS.utilSetResponseBody("Exception occurred");

                throw;
            }
        }