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

FromHeader binding #23

Closed
artyom-p opened this issue Jan 19, 2019 · 7 comments
Closed

FromHeader binding #23

artyom-p opened this issue Jan 19, 2019 · 7 comments
Assignees

Comments

@artyom-p
Copy link

Is it possible somehow to bind properties to header values?

@billbogaiv
Copy link
Owner

billbogaiv commented Jan 19, 2019

Not yet. HeaderModelBinder exists in the aspnet/Mvc repo., but it's for very simple situations. I don't know why Microsoft never added a HeaderValueProvider to go with the other value providers. I postponed writing my own thinking they would eventually do it...

@billbogaiv billbogaiv self-assigned this Jan 19, 2019
billbogaiv added a commit that referenced this issue Jan 19, 2019
New behavior mimics existing ASP.NET MVC behavior of QueryString and Form value providers.
Not really sure why this isn't included in that package.
Didn't do thorough testing, but did notice one gotcha if identical header-keys are submitted: the values are combined as a single comma-separated string.

Implements #23
billbogaiv added a commit that referenced this issue Jan 19, 2019
New behavior mimics existing ASP.NET MVC behavior of QueryString and Form value providers.
Not really sure why this isn't included in that package.
Didn't do thorough testing, but did notice one gotcha if identical header-keys are submitted: the values are combined as a single comma-separated string.

Implements #23
@billbogaiv
Copy link
Owner

🎉 https://www.nuget.org/packages/HybridModelBinding/0.13.0

public class Person
{
    [From(Source.Header)]
    public int Age { get; set; }
}
curl -X GET \
  http://localhost/ \
  -H 'Age: 42'

@artyom-p
Copy link
Author

Wow, thank you!

@artyom-p
Copy link
Author

Hey, binding works perfectly, just a small proposal, it would be great to have a possibility to override a binding name.

For example i have a header - x-request-id, and by default binder is unable to bind header to property RequestId (unfortunately it's no possible to use dashes in names).

As a solution, aditional parameter for an attribute could work. This could be also helpful not only for header binding.

billbogaiv added a commit that referenced this issue Feb 2, 2019
New behavior allows more flexibility when declaring properties as part of hybrid binding ecosystem.
This includes allowing alternate valueProvider source-naming and ordering.
The former allows using a provider (i.e. Header) with a different key than the property-name (i.e. X-Name).
The latter allows implicit (via `CallerLineNumber`) and explicit-ordering based on the line the attribute is declared (declaring multiple attributes is now allowed).

Ref. #23
billbogaiv added a commit that referenced this issue Feb 2, 2019
New behavior allows more flexibility when declaring properties as part of hybrid binding ecosystem.
This includes allowing alternate valueProvider source-naming and ordering.
The former allows using a provider (i.e. Header) with a different key than the property-name (i.e. X-Name).
The latter allows implicit (via `CallerLineNumber`) and explicit-ordering based on the line the attribute is declared (declaring multiple attributes is now allowed).

Ref. #23
billbogaiv added a commit that referenced this issue Feb 2, 2019
New behavior allows more flexibility when declaring properties as part of hybrid binding ecosystem.
This includes allowing alternate valueProvider source-naming and ordering.
The former allows using a provider (i.e. Header) with a different key than the property-name (i.e. X-Name).
The latter allows implicit (via `CallerLineNumber`) and explicit-ordering based on the line the attribute is declared (declaring multiple attributes is now allowed).

Ref. #23
billbogaiv added a commit that referenced this issue Feb 2, 2019
New behavior allows more flexibility when declaring properties as part of hybrid binding ecosystem.
This includes allowing alternate valueProvider source-naming and ordering.
The former allows using a provider (i.e. Header) with a different key than the property-name (i.e. X-Name).
The latter allows implicit (via `CallerLineNumber`) and explicit-ordering based on the line the attribute is declared (declaring multiple attributes is now allowed).

Ref. #23
billbogaiv added a commit that referenced this issue Feb 2, 2019
New behavior allows more flexibility when declaring properties as part of hybrid binding ecosystem.
This includes allowing alternate valueProvider source-naming and ordering.
The former allows using a provider (i.e. Header) with a different key than the property-name (i.e. X-Name).
The latter allows implicit (via `CallerLineNumber`) and explicit-ordering based on the line the attribute is declared (declaring multiple attributes is now allowed).

Ref. #23
billbogaiv added a commit that referenced this issue Feb 2, 2019
New behavior allows more flexibility when declaring properties as part of hybrid binding ecosystem.
This includes allowing alternate valueProvider source-naming and ordering.
The former allows using a provider (i.e. Header) with a different key than the property-name (i.e. X-Name).
The latter allows implicit (via `CallerLineNumber`) and explicit-ordering based on the line the attribute is declared (declaring multiple attributes is now allowed).

Ref. #23
billbogaiv added a commit that referenced this issue Feb 2, 2019
New behavior allows more flexibility when declaring properties as part of hybrid binding ecosystem.
This includes allowing alternate valueProvider source-naming and ordering.
The former allows using a provider (i.e. Header) with a different key than the property-name (i.e. X-Name).
The latter allows implicit (via `CallerLineNumber`) and explicit-ordering based on the line the attribute is declared (declaring multiple attributes is now allowed).

Ref. #23
billbogaiv added a commit that referenced this issue Feb 2, 2019
New behavior allows more flexibility when declaring properties as part of hybrid binding ecosystem.
This includes allowing alternate valueProvider source-naming and ordering.
The former allows using a provider (i.e. Header) with a different key than the property-name (i.e. X-Name).
The latter allows implicit (via `CallerLineNumber`) and explicit-ordering based on the line the attribute is declared (declaring multiple attributes is now allowed).

Ref. #23
@billbogaiv
Copy link
Owner

https://www.nuget.org/packages/HybridModelBinding/0.14.0 implements a new [HybridBindProperty]-attribute that will allow you to reference a separate header-name. There are some additional features which can be found in the README.

@artyom-p
Copy link
Author

artyom-p commented Feb 3, 2019

That's a great news! Great update!

@billbogaiv
Copy link
Owner

Doing some belated house cleaning. Issue has been resolved.

Rick house-cleaning

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

No branches or pull requests

2 participants