JamesRandall / FunctionMonkey

Write more elegant Azure Functions with less boilerplate, more consistency, and support for REST APIs. Docs can be found at https://functionmonkey.azurefromthetrenches.com
MIT License
294 stars 50 forks source link

How to access Cookie (and QueryString) collection ? #164

Open imanabidi opened 4 years ago

imanabidi commented 4 years ago

I need to access Cookies and Query Params inside of my handler.

I found that from the official documentation about triggercontexts that there is a way of accessing some parameters of HttpContext via IContextProvider injection which works like below code and it is very handy.

internal class CallbackHttpRequestHandler : CommandHandlerBase<CallbackHttpRequestDto, IActionResult>
  {
    private readonly IContextProvider _contextProvider;
    public CallbackHttpRequestDtoHandler(IContextProvider contextProvider) : base(false)
    {
        _contextProvider = context;
    }
    protected override async Task<IActionResult> ExecuteAsync(CallbackHttpRequestDto request,   IActionResult previousResult)
    {
        if (_contextProvider.HttpContext != null)
        {
            var headers = _context.HttpContext.Headers;
            var requestUrl = _context.HttpContext.RequestUrl;
            var claimsPrincipal = _context.HttpContext.ClaimsPrincipal;
         }
    }
  }

But there is no mapping between original HttpRequest Cookies collections and I need it.

How can I achieve that? I found it not easy inside the SDK to pass this Cookies collection. Please help.

Also posted here on SO