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

RestResponse does not contain Content-Disposition header #1684

Closed
nesc58 opened this issue Jan 7, 2022 · 4 comments
Closed

RestResponse does not contain Content-Disposition header #1684

nesc58 opened this issue Jan 7, 2022 · 4 comments

Comments

@nesc58
Copy link

nesc58 commented Jan 7, 2022

Expected Behavior

Headers should contain all headers e.g. also "Content-Disposition" header.

Actual Behavior

No Content-Disposition header is available.

Some "Content" related header values are mapped to the RestResponse object but not all headers.
https://github.com/restsharp/RestSharp/blob/dev/src/RestSharp/Response/RestResponse.cs#L111

This behavior is not listed in the migration guide.
Should I really implement this by my own?

Specifications

  • Version: 107.0.1
  • Platform: Windows - .net 5.0
  • Subsystem:
@alexeyzimarev
Copy link
Member

Could you clarify if the content-disposition header is missing in the request or you just want to have it in the response?

@nesc58
Copy link
Author

nesc58 commented Jan 7, 2022

I just want it in the response.
The behavior of the 106.* and before was: All response headers are present in the rest response.

Here is some "pseudo code" using wiremock.net:

var server = WireMockServer.Start();
server.Given(Request.Create()
        .UsingGet()
        .WithPath("/file"))
    .RespondWith(Response.Create()
        .WithStatusCode(HttpStatusCode.OK)
        .WithHeader("Content-Type", "application/pdf")
        .WithHeader("Content-Disposition", "attachment; filename=r1_name2; filename*=UTF-8''r1_name2"));

var client = new RestClient($"http://localhost:{server.Ports.FirstOrDefault()}");
var response = await client.ExecuteGetAsync(new RestRequest("/file"));

In the case of version 107.0.1 response.Headers does not contain any content related headers.

The old versions contains all headers e.g. Content-Type, Content-Length and also the Content-Disposition. These are also mapped to the response.ContentType properties but are still present in the response.Headers collection.

I am sure that this is not an error of RestSharp because the HttpResponseMessage also have a separate Content header section. I don't know what's the correct way to fix this. Adding an additional property for ContentDisposition would solve actual my problem. But what is with all other available headers in the HttpContentHeaders class?
Maybe something like .SetHeaders(httpResponse.Headers.Concat(httpResponse.Content.Headers)) could be used in RestSharp.

@alexeyzimarev
Copy link
Member

Check the last preview. RestResponse.ContentHeaders are there in a separate property. Is it a problem to have them separated? I don't really care, thought it might be useful.

I also added a property that contains the full HttpResponseMessage, which, basically, gives you access to everything.

@alexeyzimarev
Copy link
Member

107.0.2-alpha.5 has all the necessary fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants