-
Notifications
You must be signed in to change notification settings - Fork 202
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
Java - RequestConfiguration gets applied to empty headers
and options
#3378
Comments
header
s and option
sheaders
and options
Thanks for reporting this.
For both it'd be easy to add a tryadd method in the headers class and then update the request information and as well as the generation to make use of that new method. Is this something you'd be willing to submit a couple of pull requests for? |
Slowly, I probably can work on this next week or the following, instead of doing it on a case-by-case, I think that a more robust approach will be to rely on the maps already being generated instead of applying the lambda on empty parameters, does it make sense to you? |
The reason why we're working on an empty map of headers instead of the original one is because we don't want the client code to maintain a reference to the headers somehow and potentially mess things up. |
var requestInfo = new RequestInformation {
HttpMethod = Method.POST,
UrlTemplate = UrlTemplate,
PathParameters = PathParameters,
};
requestInfo.Headers.Add("Accept", "application/json");
requestInfo.SetContentFromParsable(RequestAdapter, "application/x-www-form-urlencoded", body);
if (requestConfiguration != null) {
var requestConfig = new AppsRequestBuilderPostRequestConfiguration();
requestConfiguration.Invoke(requestConfig);
requestInfo.AddRequestOptions(requestConfig.Options);
requestInfo.AddHeaders(requestConfig.Headers);
}
return requestInfo; In the above code we shouldn't be defaulting values in requestInfo if they also exist in requestConfig. We should default in the requestConfig and allow the dev to change the values and then copy back to requestInfo. |
how can they already exist in the request info if we new it up in the line right above? can you clarify please @darrelmiller? |
I was thinking along the lines of @darrelmiller something like: var requestConfig = new AppsRequestBuilderPostRequestConfiguration();
requestConfig.Headers.Add("Accept", "application/json");
...
if (requestConfiguration != null) {
requestConfiguration.Invoke(requestConfig);
}
requestInfo.AddRequestOptions(requestConfig.Options);
requestInfo.AddHeaders(requestConfig.Headers); |
Thanks for the precision here. |
The least invasive change would be to change the method wdyt? |
looking at request information itself it'd seem odd, why is it setting the body to a property of the request information but the header on an external map even though request information has one? Plus it'd be a breaking change for Go. I'm not sure what's the issue with changing the order of statements and adding try add instead like I proposed earlier? var requestInfo = new RequestInformation {
HttpMethod = Method.POST,
UrlTemplate = UrlTemplate,
PathParameters = PathParameters,
};
if (requestConfiguration != null) {
var requestConfig = new AppsRequestBuilderPostRequestConfiguration();
requestConfiguration.Invoke(requestConfig);
requestInfo.AddRequestOptions(requestConfig.Options);
requestInfo.AddHeaders(requestConfig.Headers);
}
requestInfo.SetContentFromParsable(RequestAdapter, "application/x-www-form-urlencoded", body); // switched order, uses try add
requestInfo.Headers.TryAdd("Accept", "application/json"); // switched order, uses try add
return requestInfo; |
I'm, personally, not enthusiastic about this proposal. The "solution" I would like to see here, is to be in complete control, from the user code, of the generated defaults in With this last proposal, the user is not in control, but it's allowed to "hack back" the current implementation which is not ideal. More specifically:
Instead of:
I think that a more solid design(and possibly more resilient to code-generator changes) would be to:
|
To clarify things with the approach I'm proposing:
Yes that doesn't let them set the defaults as they are setting new values, but this design also prevents the defaults from being cleared and not set afterwards, which would derail the pipeline. Lastly, if the user wants full control over the headers, they can implement a middleware handler (with or without options) |
I agree there are workarounds and here we are discussing "how to make it more convenient". I understand your motivation and tradeoffs, I think that the different bias comes from the perspective. I see this usage as "advanced" where the user deliberately wants full control. @baywet wants to prevent possible abuses in standard usage of the functionality. A third opinion would break the tie, otherwise we'd have to go with your proposed approach as it's, anyhow, an improvement over the current encoding. |
FYI we briefly talked about this one too during our brainstorming session yesterday and I was able to rally @darrelmiller to the proposal I made. If people want full control over the headers for a very advanced scenario, they have the middleware option, they can also get the request information, tweak it, and send it manually. |
ok, deal, will look into this next week likely. |
Description
Currently, to be able to manually operate on the
header
s andoption
s parameters for a given endpoint call the only viable way is to patch the already constructedRequestInformation
object.Current situation
An example RequestInformation looks as follows:
but any change to already default headers is going to be ignored, e.g.:
unexpectedly the headers are not cleaned up and the additional
Content-Type
is appended as an extra value instead of replacing the default one.Proposal
The
config
object passed to the closure should be the original one(or "a view of it") exposing the originalheaders
andoptions
fields so that a user does have idiomatic access to manipulate them.At the moment, it's possible to workaround the issue by creating the
RequestInformation
object and operating on it, such as:NOTE: given the fact that a viable workaround exists, the priority of this request should be low.
The text was updated successfully, but these errors were encountered: