Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds inspection with CDP #365

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions m365-developer-proxy-abstractions/PluginEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@
}

public class RequestLog {
public string[] Message { get; set; }
public string[] MessageLines { get; set; }
public MessageType MessageType { get; set; }
public LoggingContext? Context { get; set; }

public RequestLog(string[] message, MessageType messageType, LoggingContext? context)
public RequestLog(string[] messageLines, MessageType messageType, LoggingContext? context)
{
Message = message ?? throw new ArgumentNullException(nameof(message));
MessageLines = messageLines ?? throw new ArgumentNullException(nameof(messageLines));
MessageType = messageType;
Context = context;
}
Expand Down Expand Up @@ -187,15 +187,15 @@
}

public async Task RaiseProxyBeforeRequest(ProxyRequestArgs args) {
await BeforeRequest?.InvokeAsync(this, args, null);

Check warning on line 190 in m365-developer-proxy-abstractions/PluginEvents.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 190 in m365-developer-proxy-abstractions/PluginEvents.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.
}

public async Task RaiseProxyBeforeResponse(ProxyResponseArgs args) {
await BeforeResponse?.InvokeAsync(this, args, null);

Check warning on line 194 in m365-developer-proxy-abstractions/PluginEvents.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 194 in m365-developer-proxy-abstractions/PluginEvents.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.
}

public async Task RaiseProxyAfterResponse(ProxyResponseArgs args) {
await AfterResponse?.Invoke(this, args);

Check warning on line 198 in m365-developer-proxy-abstractions/PluginEvents.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 198 in m365-developer-proxy-abstractions/PluginEvents.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.
}

public void RaiseRequestLogged(RequestLogArgs args) {
Expand Down
3 changes: 2 additions & 1 deletion m365-developer-proxy-abstractions/ProxyUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public static IList<HttpHeader> BuildGraphResponseHeaders(Request request, strin
new HttpHeader("Strict-Transport-Security", ""),
new HttpHeader("request-id", requestId),
new HttpHeader("client-request-id", requestId),
new HttpHeader("Date", requestDate)
new HttpHeader("Date", requestDate),
new HttpHeader("Content-Type", "application/json")
};
if (request.Headers.FirstOrDefault((h) => h.Name.Equals("Origin", StringComparison.OrdinalIgnoreCase)) is not null) {
headers.Add(new HttpHeader("Access-Control-Allow-Origin", "*"));
Expand Down
294 changes: 294 additions & 0 deletions m365-developer-proxy-plugins/Inspection/CDPModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json.Serialization;
using Microsoft365.DeveloperProxy.Abstractions;

// CDP = Chrome DevTools Protocol
namespace Microsoft365.DeveloperProxy.Plugins.Inspection.CDP;

public class RequestWillBeSentExtraInfoMessage : Message<RequestWillBeSentExtraInfoParams>
{
public RequestWillBeSentExtraInfoMessage()
{
Method = "Network.requestWillBeSentExtraInfo";
}
}

public class RequestWillBeSentExtraInfoParams
{
[JsonPropertyName("requestId")]
public string? RequestId { get; set; }

[JsonPropertyName("associatedCookies")]
public object[]? AssociatedCookies { get; set; }

[JsonPropertyName("headers")]
public Dictionary<string, string>? Headers { get; set; }
}

public class RequestWillBeSentMessage : Message<RequestWillBeSentParams>
{
public RequestWillBeSentMessage()
{
Method = "Network.requestWillBeSent";
}
}

public class RequestWillBeSentParams
{
[JsonPropertyName("requestId")]
public string? RequestId { get; set; }
[JsonPropertyName("loaderId")]
public string? LoaderId { get; set; }
[JsonPropertyName("documentURL")]
public string? DocumentUrl { get; set; }
[JsonPropertyName("request")]
public Request? Request { get; set; }
[JsonPropertyName("timestamp")]
public double? Timestamp { get; set; }
[JsonPropertyName("wallTime")]
public long? WallTime { get; set; }
[JsonPropertyName("initiator")]
public Initiator? Initiator { get; set; }
}

public class ResponseReceivedMessage : Message<ResponseReceivedParams>
{
public ResponseReceivedMessage()
{
Method = "Network.responseReceived";
}
}

public class ResponseReceivedParams
{
[JsonPropertyName("requestId")]
public string? RequestId { get; set; }

[JsonPropertyName("loaderId")]
public string? LoaderId { get; set; }

[JsonPropertyName("timestamp")]
public double? Timestamp { get; set; }

[JsonPropertyName("type")]
public string? Type { get; set; }

[JsonPropertyName("response")]
public Response? Response { get; set; }

[JsonPropertyName("hasExtraInfo")]
public bool? HasExtraInfo { get; set; }

[JsonPropertyName("frameId")]
public string? FrameId { get; set; }
}

public class Response
{
[JsonPropertyName("url")]
public string? Url { get; set; }

[JsonPropertyName("status")]
public int? Status { get; set; }

[JsonPropertyName("statusText")]
public string? StatusText { get; set; }

[JsonPropertyName("headers")]
public Dictionary<string, string>? Headers { get; set; }

[JsonPropertyName("mimeType")]
public string? MimeType { get; set; }

[JsonPropertyName("connectionReused")]
public bool? ConnectionReused { get; set; }

[JsonPropertyName("connectionId")]
public int? ConnectionId { get; set; }

[JsonPropertyName("fromDiskCache")]
public bool? FromDiskCache { get; set; }

[JsonPropertyName("fromServiceWorker")]
public bool? FromServiceWorker { get; set; }

[JsonPropertyName("fromPrefetchCache")]
public bool? FromPrefetchCache { get; set; }

[JsonPropertyName("encodedDataLength")]
public int? EncodedDataLength { get; set; }

[JsonPropertyName("protocol")]
public string? Protocol { get; set; }

[JsonPropertyName("alternateProtocolUsage")]
public string? AlternateProtocolUsage { get; set; }

[JsonPropertyName("securityState")]
public string? SecurityState { get; set; }
}

public class Request
{
[JsonPropertyName("url")]
public string? Url { get; set; }
[JsonPropertyName("method")]
public string? Method { get; set; }
[JsonPropertyName("headers")]
public Dictionary<string, string>? Headers { get; set; }
[JsonPropertyName("postData")]
public string? PostData { get; set; }
}

public class Initiator
{
[JsonPropertyName("type")]
public string? Type { get; set; }
}

public class LoadingFinishedMessage : Message<LoadingFinishedParams>
{
public LoadingFinishedMessage()
{
Method = "Network.loadingFinished";
}
}

public class LoadingFinishedParams
{
[JsonPropertyName("requestId")]
public string? RequestId { get; set; }

[JsonPropertyName("timestamp")]
public double? Timestamp { get; set; }

[JsonPropertyName("encodedDataLength")]
public long? EncodedDataLength { get; set; }
}

public class LoadingFailedMessage : Message<LoadingFailedParams>
{
public LoadingFailedMessage()
{
Method = "Network.loadingFailed";
}
}

public class LoadingFailedParams
{
[JsonPropertyName("requestId")]
public string? RequestId { get; set; }

[JsonPropertyName("timestamp")]
public double? Timestamp { get; set; }

[JsonPropertyName("type")]
public string? Type { get; set; }

[JsonPropertyName("errorText")]
public string? ErrorText { get; set; }

[JsonPropertyName("canceled")]
public bool? Canceled { get; set; }

[JsonPropertyName("blockedReason")]
public string? BlockedReason { get; set; }
}

public class EntryAddedMessage : Message<EntryAddedParams>
{
public EntryAddedMessage()
{
Method = "Log.entryAdded";
}
}

public class EntryAddedParams
{
[JsonPropertyName("entry")]
public Entry? Entry { get; set; }
}

public class Entry
{
[JsonPropertyName("source")]
public string? Source { get; set; }
[JsonPropertyName("level")]
public string? Level { get; set; }
[JsonPropertyName("text")]
public string? Text { get; set; }
[JsonPropertyName("timestamp")]
public double? Timestamp { get; set; }
[JsonPropertyName("url")]
public string? Url { get; set; }
[JsonPropertyName("networkRequestId")]
public string? NetworkRequestId { get; set; }

public static string GetLevel(MessageType messageType)
{
return messageType switch
{
MessageType.Normal => "info",
MessageType.InterceptedRequest => "info",
MessageType.PassedThrough => "info",
MessageType.Warning => "warning",
MessageType.Tip => "info",
MessageType.Failed => "error",
MessageType.Chaos => "error",
MessageType.Mocked => "info",
MessageType.InterceptedResponse => "info",
_ => "info"
};
}
}

public class GetResponseBodyMessage : Message<GetResponseBodyParams>
{
public GetResponseBodyMessage()
{
Method = "Network.getResponseBody";
}
}

public class GetResponseBodyParams
{
[JsonPropertyName("requestId")]
public string? RequestId { get; set; }
}

public class GetResponseBodyResult : MessageResult<GetResponseBodyResultParams>
{
}

public class GetResponseBodyResultParams
{
[JsonPropertyName("body")]
public string? Body { get; set; }
[JsonPropertyName("base64Encoded")]
public bool? Base64Encoded { get; set; }
}

public abstract class MessageResult<TResult>
{
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("result")]
public TResult? Result { get; set; }
}

public abstract class Message
{
[JsonPropertyName("id")]
public int? Id { get; set; }

[JsonPropertyName("method")]
public string? Method { get; set; }
}

public abstract class Message<TParams> : Message
{
[JsonPropertyName("params")]
public TParams? Params { get; set; }
}
Loading
Loading