question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exposing response headers through a generated C# client

See original GitHub issue

Preface: I want to implement the ETag header for some of my resources. My initial plan is to use [SwaggerResponse(HttpStatusCode.NotModified, typeof(void))] and handle ETag logic inside the action.

For the above to work, I need to be able to read the response headers with my generated clients, to extract the current ETag. I’m not quite sure how this can be achieved without breaking existing code. Perhaps a new generator setting can be added, to have methods return value tuples containing the response headers. So instead of

Task<Foo> Foos_GetFooAsync(int id)

it generates

Task<(Foo value, HttpResponseHeaders responseHeaders)> Foos_GetFooAsync(int id)

Then you can either use the headers

(var foo, var headers) = await Foos_GetFooAsync(id)

or discard them

(var foo, _) = await Foos_GetFooAsync(id)

Do you think this is a path worth exploring? Or do you have something else in mind? I can help out with implementing this if you like.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
stijnherremancommented, Oct 25, 2017

Ah, thank you. The client name is Client in this case, so Client.Workspaces_Head made it work.

1reaction
RicoSutercommented, Oct 25, 2017

I think it’s clientName.methodName

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exposing response headers through a generated C# client
Preface: I want to implement the ETag header for some of my resources. My initial plan is to use [SwaggerResponse(HttpStatusCode.
Read more >
How do I expose a WCF web service call response header ...
My problem is that I want to expose the actual HTTP header received in the above call, such as client.GetHttpResponse() or something.
Read more >
Access-Control-Expose-Headers - HTTP - MDN Web Docs
The Access-Control-Expose-Headers response header allows a server to indicate which response headers should be made available to scripts ...
Read more >
HTTP Security Response Headers Cheat Sheet
Proper HTTP response headers can help prevent security vulnerabilities like Cross-Site Scripting, Clickjacking, Information disclosure and more. In this cheat ...
Read more >
Response Header - an overview
Most actionable response headers are generated by the Web server itself. These include instructions for the client to cache the content (or not), ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found