本文整理汇总了C#中Fiddler.Session.utilCreateResponseAndBypassServer方法的典型用法代码示例。如果您正苦于以下问题:C# Session.utilCreateResponseAndBypassServer方法的具体用法?C# Session.utilCreateResponseAndBypassServer怎么用?C# Session.utilCreateResponseAndBypassServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fiddler.Session
的用法示例。
在下文中一共展示了Session.utilCreateResponseAndBypassServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadFile
void LoadFile(string rpFilename, ResourceSession rpResourceSession, Session rpSession)
{
if (!rpSession.bBufferResponse)
rpSession.utilCreateResponseAndBypassServer();
rpSession.ResponseBody = File.ReadAllBytes(rpFilename);
rpSession.oResponse["Server"] = "Apache";
rpSession.oResponse["Connection"] = "close";
rpSession.oResponse["Accept-Ranges"] = "bytes";
rpSession.oResponse["Cache-Control"] = "max-age=18000, public";
rpSession.oResponse["Date"] = DateTime.Now.ToString("R");
if (rpFilename.EndsWith(".swf", StringComparison.OrdinalIgnoreCase))
rpSession.oResponse["Content-Type"] = "application/x-shockwave-flash";
else if (rpFilename.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase))
rpSession.oResponse["Content-Type"] = "audio/mpeg";
else if (rpFilename.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
rpSession.oResponse["Content-Type"] = "image/png";
else if (rpFilename.EndsWith(".css", StringComparison.OrdinalIgnoreCase))
rpSession.oResponse["Content-Type"] = "text/css";
else if (rpFilename.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
rpSession.oResponse["Content-Type"] = "application/x-javascript";
rpResourceSession.State = NetworkSessionState.LoadedFromCache;
}
示例2: ProcessRequest
internal void ProcessRequest(ResourceSession rpResourceSession, Session rpSession)
{
if (CurrentMode == CacheMode.Disabled)
return;
string rFilename;
var rNoVerification = CheckFileInCache(rpResourceSession.Path, out rFilename);
rpResourceSession.CacheFilename = rFilename;
if (rNoVerification == null)
return;
if (!rNoVerification.Value)
{
var rTimestamp = new DateTimeOffset(File.GetLastWriteTime(rFilename));
if (rpResourceSession.Path.OICContains("mainD2.swf") || rpResourceSession.Path.OICContains(".js") || !CheckFileVersionAndTimestamp(rpResourceSession, rTimestamp))
{
rpSession.oRequest["If-Modified-Since"] = rTimestamp.ToString("R");
rpSession.bBufferResponse = true;
return;
}
}
rpSession.utilCreateResponseAndBypassServer();
LoadFile(rFilename, rpResourceSession, rpSession);
}
示例3: _BeforeRequest
//This event fires when a client request is received by Fiddler
static void _BeforeRequest(Session oSession)
{
if (!Settings.Current.CacheEnabled) return;
if (!_Filter(oSession)) return;
string filepath;
var direction = cache.GotNewRequest(oSession.fullUrl, out filepath);
if (direction == Direction.Return_LocalFile)
{
//返回本地文件
oSession.utilCreateResponseAndBypassServer();
oSession.ResponseBody = File.ReadAllBytes(filepath);
_CreateResponseHeader(oSession, filepath);
//Debug.WriteLine("CACHR> 【返回本地】" + filepath);
}
else if (direction == Direction.Verify_LocalFile)
{
//请求服务器验证文件
//oSession.oRequest.headers["If-Modified-Since"] = result;
oSession.oRequest.headers["If-Modified-Since"] = _GetModifiedTime(filepath);
oSession.bBufferResponse = true;
//Debug.WriteLine("CACHR> 【验证文件】" + oSession.PathAndQuery);
}
else
{
//下载文件
}
}
示例4: FiddlerApplication_BeforeRequest
private void FiddlerApplication_BeforeRequest(Session oSession)
{
if (!set.CacheEnabled) return;
if (oSession.PathAndQuery.StartsWith("/kcsapi/api_req_furniture/music_play") && set.HackMusicRequestEnabled)
{
oSession.utilCreateResponseAndBypassServer();
oSession.oResponse.headers.Add("Content-Type", "text/plain");
oSession.utilSetResponseBody(@"svdata={""api_result"":1,""api_result_msg"":""\u6210\u529f"",""api_data"":{""api_coin"":" + fcoin.ToString() + @"}}");
}
else if (oSession.PathAndQuery.StartsWith("/kcsapi/api_get_member/picture_book") && set.HackBookEnabled)
{
oSession.utilCreateResponseAndBypassServer();
oSession.oResponse.headers.Add("Content-Type", "text/plain");
int type = 1; // 1: 舰娘图鉴, 2: 装备图鉴
int no = 1; // 页数
var param = oSession.GetRequestBodyAsString().Split('&');
foreach (var p in param)
{
var kv = p.Split('=');
if (kv[0] == "api%5Ftype")
{
type = int.Parse(kv[1]);
}
else if (kv[0] == "api%5Fno")
{
no = int.Parse(kv[1]);
}
}
if (type == 1)
{
oSession.utilSetResponseBody("svdata=" + ShipBookData.Generate(initData, no * 70 - 69, no * 70).ToJsonString());
}
else
{
oSession.utilSetResponseBody("svdata=" + EquipmentBookData.Generate(initData, no * 50 - 49, no * 50).ToJsonString());
}
}
}
示例5: BeforeRequest
public static void BeforeRequest(Session oS)
{
var file = oS.url.Replace('/', '_').Split('?').First();
var method = oS.HTTPMethodIs("GET") ? "GET"
: oS.HTTPMethodIs("POST") ? "POST"
: oS.HTTPMethodIs("PUT") ? "PUT" : null;
oS.utilCreateResponseAndBypassServer();
var lines = File.ReadAllLines("./Api/Data/" + method + " " + file + ".txt");
oS.oResponse.headers = Parser.ParseResponse(lines.First());
oS.oResponse.headers.Add("Content-Type", "application/json");
oS.utilSetResponseBody(String.Join(Environment.NewLine, lines.Skip(2).ToArray()));
}
示例6: AutoTamperRequestBefore
public void AutoTamperRequestBefore(Session session)
{
if (Settings.enabled && session.HostnameIs(reportHost) && !session.isFTP)
{
// TODO: We should offer an option to hide the reports from Fiddler; change "ui-strikeout" to "ui-hide" in the next line
session["ui-strikeout"] = "CSPReportGenerator";
if (!session.HTTPMethodIs("CONNECT"))
{
session.utilCreateResponseAndBypassServer();
session.oResponse.headers.Add("Content-Type", "text/html");
session.ResponseBody = Encoding.UTF8.GetBytes("<!doctype html><HTML><BODY><H1>Report received.</H1></BODY></HTML>");
ProcessCSPReport(session);
}
else
{
session["x-replywithtunnel"] = "CSPReportGenerator";
}
}
}
示例7: FiddlerApplication_BeforeRequest
private void FiddlerApplication_BeforeRequest(Session oSession) {
// using proxy
if (Utility.Config.Instance.UseUpstreamProxy) {
oSession["X-OverrideGateway"] = string.Format("{0}:{1}", Utility.Config.Instance.UpstreamProxyHost, Utility.Config.Instance.UpstreamProxyPort);
}
if (oSession.PathAndQuery.StartsWith("/kcs/")) {
string filePath;
var direction = Cache.GotNewRequest(oSession.PathAndQuery, out filePath);
if (direction == Direction.Return_LocalFile) {
// 返回本地文件
oSession.utilCreateResponseAndBypassServer();
oSession.oResponse.headers.HTTPResponseCode = 304;
Utility.Logger.Add("Request > [使用本地文件]" + filePath);
} else if (direction == Direction.Verify_LocalFile) {
// 請求驗證
oSession.oRequest.headers["If-Modified-Since"] = GMTHelper._GetModifiedTime(filePath);
oSession.bBufferResponse = true;
Utility.Logger.Add("Request > [驗證本地文件]" + oSession.PathAndQuery);
} else if (direction == Direction.Discharge_Response) {
Utility.Logger.Add("Request > [重新下載]" + oSession.PathAndQuery);
}
} else if (oSession.PathAndQuery.StartsWith("/kcsapi/")) {
if (oSession.PathAndQuery.StartsWith("/kcsapi/api_start2")) {
oSession.bBufferResponse = true;
}
}
}
示例8: runApiMode
// api 모드 실행
void runApiMode(Session oSession)
{
PLinkApiType data = router(oSession.PathAndQuery);
if (data == null) {
oSession.oRequest.pipeClient.End();
} else {
SetDiabledCache(oSession);
// 새로운 응답 만들기
oSession.utilCreateResponseAndBypassServer();
oSession.oResponse.headers.HTTPResponseCode = 200;
oSession.oResponse.headers.HTTPResponseStatus = "200 OK";
oSession.oResponse.headers["Content-Type"] = data.ContentType;
SetDiabledCacheAfter(oSession);
oSession.utilSetResponseBody(data.Body);
}
}
示例9: EchoEntry
private static void EchoEntry(Session session)
{
Uri hostName = new Uri(string.Format("http://{0}/", session.oRequest["Host"]));
Uri tableUrl = new Uri(session.fullUrl);
string requestString = session.GetRequestBodyAsString();
string timestamp = DateTime.UtcNow.ToString("o");
string etag = string.Format("W/\"datetime'{0}'\"", Uri.EscapeDataString(timestamp));
XElement request = XElement.Parse(requestString);
request.SetAttributeValue(XNamespace.Xml + "base", hostName.AbsoluteUri);
request.SetAttributeValue(TableConstants.Metadata + "etag", Uri.EscapeDataString(etag));
string partitionKey = request.Descendants(TableConstants.OData + "PartitionKey").Single().Value;
string rowKey = request.Descendants(TableConstants.OData + "RowKey").Single().Value;
Uri entryUri = new Uri(string.Format(
"{0}(PartitionKey='{1}',RowKey='{2}')",
tableUrl.AbsoluteUri,
Uri.EscapeUriString(partitionKey),
Uri.EscapeUriString(rowKey)));
XElement timestampElement = request.Descendants(TableConstants.OData + "Timestamp").Single();
timestampElement.Value = timestamp;
XElement updatedElement = request.Descendants(TableConstants.Atom + "updated").Single();
updatedElement.Value = timestamp;
XElement idElement = request.Descendants(TableConstants.Atom + "id").Single();
idElement.Value = entryUri.AbsoluteUri;
// Add link
XElement linkElement = new XElement(
TableConstants.Atom + "link",
new XAttribute("rel", "edit"),
new XAttribute("href", entryUri.PathAndQuery.Substring(1)));
idElement.AddAfterSelf(linkElement);
// Add category
string accountName = hostName.Host.Substring(0, hostName.Host.IndexOf('.'));
string categoryName = accountName + "." + tableUrl.PathAndQuery.Substring(1);
idElement.AddAfterSelf(TableConstants.GetCategory(categoryName));
// mark that we're going to tamper with it
session.utilCreateResponseAndBypassServer();
session.oResponse.headers = CreateResponseHeaders(entryUri.AbsoluteUri);
session.oResponse.headers["ETag"] = etag;
session.responseCode = 201;
string responseString = request.ToString();
session.utilSetResponseBody(responseString);
}
示例10: CreateTableError
/// <summary>
/// CreateTableError creates an error response from a table API.
/// </summary>
/// <param name="session">The session with which to tamper.</param>
/// <param name="statusCode">The error code to return</param>
/// <param name="messageCode">The string name for the error</param>
/// <param name="message">The long error message to be returned.</param>
private static void CreateTableError(Session session, int statusCode, string messageCode, string message)
{
session.utilCreateResponseAndBypassServer();
session.oResponse.headers = CreateResponseHeaders(null);
session.responseCode = statusCode;
session.utilSetResponseBody(
TableConstants.GetError(
messageCode,
string.Format(
"{0}\r\nRequestId:{1}\r\nTime:{2}",
message,
Guid.Empty.ToString(),
DateTime.UtcNow.ToString("o"))).ToString());
}
示例11: GetTableWithCode
/// <summary>
/// GetTableWithCode tampers with with the request to return the specific table and a success code.
/// </summary>
/// <param name="session"></param>
/// <param name="statusCode"></param>
private static void GetTableWithCode(Session session, int statusCode)
{
// Find relevant facts about this table creation.
Uri hostName = new Uri(string.Format("http://{0}/", session.oRequest["Host"]));
string requestString = session.GetRequestBodyAsString();
string tableName = null;
string tableUri = null;
if (string.IsNullOrEmpty(requestString))
{
tableName = tableNameRegex.Match(session.url).Groups[1].Value;
}
else
{
XElement request = XElement.Parse(requestString);
tableName = request.Descendants(TableConstants.OData + "TableName").Single().Value;
tableUri = new Uri(hostName, string.Format("/Tables('{0}')", tableName)).AbsoluteUri;
}
// mark that we're going to tamper with it
session.utilCreateResponseAndBypassServer();
session.oResponse.headers = CreateResponseHeaders(tableUri);
session.responseCode = statusCode;
// Create the response XML
XElement response = TableConstants.GetEntry(hostName.AbsoluteUri);
response.Add(new XElement(TableConstants.Atom + "id", session.fullUrl));
response.Add(new XElement(TableConstants.Title));
response.Add(new XElement(TableConstants.Atom + "updated", DateTime.UtcNow.ToString("o")));
response.Add(TableConstants.Author);
response.Add(TableConstants.GetLink(tableName));
string accountName = hostName.Host.Substring(0, hostName.Host.IndexOf('.'));
response.Add(TableConstants.GetCategory(accountName + ".Tables"));
// Add in the most important part -- the table name.
response.Add(new XElement(
TableConstants.Atom + "content",
new XAttribute("type", "application/xml"),
new XElement(
TableConstants.Metadata + "properties",
new XElement(
TableConstants.OData + "TableName",
tableName))));
string responseString = response.ToString();
session.utilSetResponseBody(responseString);
}
示例12: sendResponse
void sendResponse(Session oSession, int code, string content_type, byte[] data)
{
oSession.utilCreateResponseAndBypassServer();
oSession.oResponse.headers.HTTPResponseCode = code;
string status = Util.getStatus(code);
oSession.oResponse.headers.HTTPResponseStatus = status;
oSession.oResponse.headers["Content-Type"] = content_type;
//oSession.oResponse.headers["Content-Length"] = data.Length.ToString();
log(data.ToString());
oSession.ResponseBody = data;
}
示例13: LoadFromCacheCore
static void LoadFromCacheCore(FiddlerSession rpSession, ResourceSession rpResourceSession, string rpPath)
{
rpSession.utilCreateResponseAndBypassServer();
rpSession.ResponseBody = File.ReadAllBytes(rpPath);
rpResourceSession.LoadedBytes = rpSession.ResponseBody.Length;
rpResourceSession.Status = SessionStatus.LoadedFromCache;
}
示例14: _BeforeRequest
//This event fires when a client request is received by Fiddler
static void _BeforeRequest(Session oSession)
{
if (!Settings.Current.CacheEnabled) return;
if (!_Filter(oSession)) return;
string filepath;
var direction = cache.GotNewRequest(oSession.fullUrl, out filepath);
if (direction == Direction.Return_LocalFile)
{
//返回本地文件
oSession.utilCreateResponseAndBypassServer();
byte[] file;
using (var fs = File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
file = new byte[fs.Length];
fs.Read(file, 0, (int)fs.Length);
}
oSession.ResponseBody = file;
_CreateResponseHeader(oSession, filepath);
//Debug.WriteLine("CACHR> 【返回本地】" + filepath);
}
else if (direction == Direction.Verify_LocalFile)
{
//请求服务器验证文件
//oSession.oRequest.headers["If-Modified-Since"] = result;
oSession.oRequest.headers["If-Modified-Since"] = _GetModifiedTime(filepath);
oSession.bBufferResponse = true;
//Debug.WriteLine("CACHR> 【验证文件】" + oSession.PathAndQuery);
}
else
{
//下载文件
}
}
示例15: _returnRootCert
private static void _returnRootCert(Session oS)
{
oS.utilCreateResponseAndBypassServer();
oS.oResponse.headers["Connection"] = "close";
oS.oResponse.headers["Cache-Control"] = "max-age=0";
byte[] buffer = CertMaker.getRootCertBytes();
if (buffer != null)
{
oS.oResponse.headers["Content-Type"] = "application/x-x509-ca-cert";
oS.responseBodyBytes = buffer;
oS.oResponse.headers["Content-Length"] = oS.responseBodyBytes.Length.ToString();
}
else
{
oS.responseCode = 0x194;
oS.oResponse.headers["Content-Type"] = "text/html; charset=UTF-8";
oS.utilSetResponseBody("No root certificate was found. Have you enabled HTTPS traffic decryption in Fiddler yet?".PadRight(0x200, ' '));
}
FiddlerApplication.DoResponseHeadersAvailable(oS);
oS.ReturnResponse(false);
}