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.

[data-plane priority] Content-Type header parameter next to binary/stream body parameter

See original GitHub issue

On our road to enable data plane generation, we (the C# people) have hit a slightly problematic scenario that was no supported in C# but is now. Please make sure it is also supported in your respective language.

Scenario

An API call accepts images (i.e. binary data) that can be of different types, say image/png or image/jpeg. The Swagger for this call says consumes: ['image/png', 'image/jpeg'], accordingly. Since our generated clients accept raw binary data or a stream, we have to enable users to specify the content type header of that data, as otherwise what header are we gonna send? So far so good, so you add a header parameter called Content-Type to your Swagger.

Problem 1

According to the OpenAPI standard, a header parameter called Content-Type are to be ignored as if it was not specified at all. I guess their idea is that the content type should be fully derivable from the request body, which usually makes sense (why would you offer the opportunity to specify and hence possibly screw up derivable information… just derive it). However, in this very scenario (I think binary data in general), there is no practical way to derive the content type!

Solution

AutoRest has always ignored that part of the spec, so “you guys” (the language generator) will see the parameters show up on your side already, sweet.

Problem 2

The generated code may not do the “right thing” with the parameter. This hit us in C# since the method to add custom headers to an HTTP request rejects any attempts to set Content-Type (“this is special, please use the dedicated property, blablabla”).

Solution

Make sure your generator does the right thing and generates working code (note that the C# bug was only exposed at runtime). If not, please fix it.

Example and Testing Strategy

I’ve added an example testing for this very behavior, feel free to use this example as your test case. Ideally, you can just check if the generated code in there works up to the point where a correct HTTP request is sent out. Note that the configuration file also contains some more details about what changes I did for C# and language agnostically, maybe it helps.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
jianghaolucommented, Jul 5, 2017

Verified in Java overwriting Content-Type is allowed.

1reaction
sarangan12commented, Jul 7, 2017

Synched up with @olydis and cleared up the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

4 The Content-Type Header Field
The Content-Type header field is used to specify the nature of the data in the body of an entity, by giving type and...
Read more >
Quickstart — Requests 2.28.1 documentation
If you'd like to add HTTP headers to a request, simply pass in a dict to the headers parameter. ... Note: Custom headers...
Read more >
Annotated services — Armeria documentation
Injecting value of parameters and HTTP headers into a Java object ... If an HTTP POST request with a Content-Type: x-www-form-urlencoded header is...
Read more >
Session Initiation Protocol (SIP) Parameters
Some headers have single-letter compact forms (Section 7.3 of RFC 3261). Header field names are case-insensitive. Standard header fields and ...
Read more >
Building requests | Postman Learning Center
Otherwise, specify your parameters and any body data you need to send ... a Content-Type header, that value will take precedence over what ......
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