Skip to content

Add debug output to HttpContext and friends #48293

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

Merged
merged 6 commits into from
May 19, 2023

Conversation

Tratcher
Copy link
Member

@Tratcher Tratcher commented May 17, 2023

Contributes to #48205

I've added debug views to HttpContext and related types. While some of the views appear to be pass through, they actually work to hide internal implementation details from the underlying types. Note we can't put debug views on interfaces so I had to do it directly on implementing types. IIS and HttpSys share a header collection implementation.

The ToString implementations are optional, we could make those private string CreateDebugView() instead.

Other properties to consider:

  • Features/FeatureCollection

image

@JamesNK
Copy link
Member

JamesNK commented May 18, 2023

HttpContext.User isn't that useful. An issue to embiggen its debug capabilities: dotnet/runtime#86421

@JamesNK
Copy link
Member

JamesNK commented May 18, 2023

Something we should consider is the formatting of properties and values. Existing debugger display attributes tend to use the format IsCancellationRequested = true and Count = 10 while we do IsCancellationRequested: true, which is the format we tend to use in our logging messages.

Idea: We stick with our format Name: value for logs and endpoint metadata and use the equals format Name = value for debugger display. What do you think @Tratcher?

@Tratcher
Copy link
Member Author

Something we should consider is the formatting of properties and values. Existing debugger display attributes tend to use the format IsCancellationRequested = true and Count = 10 while we do IsCancellationRequested: true, which is the format we tend to use in our logging messages.

Idea: We stick with our format Name: value for logs and endpoint metadata and use the equals format Name = value for debugger display. What do you think @Tratcher?

I switched to using = and it seems fine. The one place it's a little odd is when I'm only naming some paramters for brevity:
HttpContext: POST /path application/json StatusCode = 200 application/json
Request: HTTP/2 POST https://Host:port/pathBase/path?q1=1&q2=2 application/json Length = 10
Response: StatusCode = 200, HasStarted = False, Length = (null) application/json
Connection: Id = ConId, Remote = [::1]:12345, Local = [::1]:443, ClientCertificate = (null)

I want things to easily fit into the debug window, and most of these fields seem obvious from context. The expanded view breaks down the individual fields.

@Tratcher Tratcher requested a review from JamesNK May 18, 2023 23:35
@JamesNK JamesNK enabled auto-merge (squash) May 19, 2023 00:28
@JamesNK JamesNK merged commit 631f523 into dotnet:main May 19, 2023
@ghost ghost added this to the 8.0-preview5 milestone May 19, 2023
@Tratcher Tratcher deleted the tratcher/debugHttp branch May 19, 2023 15:53
@amcasey amcasey added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants