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

Keep the - of header on init parameter names, otherwise the nested path will not work. #34193

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

remeio
Copy link
Contributor

@remeio remeio commented Jan 4, 2025

Keep the - of header names when init parameter names, otherwise the nested path will not work.

@rstoyanchev Hi, for property name and parameter name, I think they should use the same transformed header name using "camelCase".

For example, A http request with headers:

  • User-Agent: something
  • WWW-Authenticate: something

Before this PR, the method ExtendedServletRequestValueResolver#initParameterNames will return a name set:

  • UserAgent, WWWAuthenticate

After this PR, the method will return a name set:

  • userAgent, wWWAuthenticate

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 4, 2025
@remeio remeio changed the title Transform header name to property name using "camelCase" Transform header name same with property name Jan 4, 2025
@bclozel bclozel added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jan 6, 2025
@bclozel bclozel self-assigned this Jan 7, 2025
@bclozel
Copy link
Member

bclozel commented Jan 8, 2025

@remeio Can you elaborate on which use case you're trying to solve here?
Could you share a sample controller and data class to be bound to explain what's missing here?

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Jan 8, 2025
…path will not work.

Signed-off-by: Mengqi Xu <2663479778@qq.com>
@remeio remeio force-pushed the transform_header_name branch from efbdf84 to 89a90f1 Compare January 8, 2025 15:37
@remeio remeio changed the title Transform header name same with property name Keep the - of header on init parameter names, otherwise the nested path will not work. Jan 8, 2025
@remeio
Copy link
Contributor Author

remeio commented Jan 8, 2025

@remeio Can you elaborate on which use case you're trying to solve here? Could you share a sample controller and data class to be bound to explain what's missing here?

@bclozel Hi, I had changed the content of this PR , you can look the test case.

I think it's not correct for replace the - of header names when init parameter names, because the nested path will not work.

@bclozel
Copy link
Member

bclozel commented Jan 8, 2025

I missed the fact that this was for nested parameters, indeed. Thanks for clarifying that and adding a test case.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 8, 2025
@bclozel bclozel added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Jan 8, 2025
@bclozel bclozel modified the milestone: 6.2.2 Jan 8, 2025
@bclozel bclozel added status: waiting-for-triage An issue we've not yet triaged or decided on and removed type: bug A general bug labels Jan 8, 2025
@bclozel
Copy link
Member

bclozel commented Jan 8, 2025

I'm not sure about this change after all.

When binding bean properties, the following case will work:

class Person() {

  // will bind HTTP header "First-Name" : "Jane"
  String firstName;

  public String getFirstName() {
    //
  }
  public String setFirstName(String firstName) {
    //
  }
}

Constructor binding requires the @BindParam for the same behavior

// will bind HTTP header "First-Name" : "Jane"
record Person(@BindParam("First-Name") String firstName) {
}

This PR is about supporting the nested case like so:

record MyAddress(@BindParam("My-Address") Address myAddress) {
}

// will bind HTTP header "My-Address.Street-Name" : "Spring Street"
record Address(@BindParam("Street-Name") String streetName) {
}

The ABNF of RFC7230 allows "." in header names:

header-field = field-name ":" OWS field-value OWS
field-name = token
token = 1tchar
tchar = "!" / "#" / "$" / "%" / "&" / "'" / "
" / "+" / "-" / "." /
"^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA

But in practice, I'm wondering if we should rely on "." characters in header names. Proxies and CDNs might not accept it.

What do you think @rstoyanchev ?

@bclozel bclozel added the status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants