2

I'm looking how to get a custom header value from a received WSF_REQUEST. I read the docs quickly and didn't find the answer.

'Authorization': 'Bearer my_long_token'
Pipo
  • 4,653
  • 38
  • 47

2 Answers2

2

Use http_authorization from the WSF_REQUEST interface. (all the request header values are available using the CGI convention, mostly prefixing with HTTP_ , all in uppercase, and using _ as separator.

Jocelyn
  • 693
  • 5
  • 8
1

My complete solution was

last_request: detachable WSF_REQUEST

find_it
    do
        if attached header_item ("HTTP_AUTHORIZATION") as l_bearer then
            do_something (l_bearer)
        end
    end

meta_variable, header_item (a_key: STRING): detachable STRING
    require
        attached last_request -- {WSF_REQUEST}
    do
        check
            attached last_request as l_last_request
        then
            across
                l_last_request.meta_variables as l_item_cursor
            until
                attached Result
            loop
                --logger.write_debug ("header_item->key:" + l_item_cursor.item.name + " val:" + l_item_cursor.item.value)
                if l_item_cursor.item.name.is_equal (a_key) then
                    Result := l_item_cursor.item.value
                end
            end
        end
    end
Pipo
  • 4,653
  • 38
  • 47
  • Unrelated to your question and only as a point of naming convention: I name "attachment locals" like `l_last_request` as `al_last_request`, so they are not confused with `local` variables, where I use an `l_` prefix. Also, the across loop `l_item_cursor` is where I will generally use just `ic` (or `ic_?` as a prefix) for "iteration cursor". In this case, your code would read, `... as ic` and then `if ic.item.name.is_equal (a_key) then ...`. I also use this across-loop naming convention for symbolic loops as well (e.g. `⟳ ... ⟲`). – Liberty Lover Aug 20 '22 at 16:32