Access headers in order

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • netblazon
    Developer Partner




    • Mar 2006
    • 717

    #1

    Access headers in order

    I'm working on an integration where I need to access and provide the HTTP headers (just the names, not the values) in the order they were sent to the script. So I would build a string such as:
    Host,Connection,Cookie,Cache-Control
    Now I know I can look at those individually, such as s.http_host, s.http_cache_control, etc. But in order to do that, I already have to know which ones were sent (or at least a superset of all that could be sent). And I wouldn't have them in the same order as they were presented to the script.

    Is there a way I can just access the raw headers themselves?
    Thanks,
    Susan
    Susan Petracco
    NetBlazon

    1.866.400.2444

    _____________________________________________

    Like us on Facebook
  • wmgilligan
    Developer Partner




    • Feb 2006
    • 742

    #2
    If I am reading right, this should help:
    Code:
    <MvFunction name="getSession" parameters="sessInfo" standardoutputlevel="html,text,compresswhitespace">
       <MvASSIGN NAME = "l.cookies" VALUE = "">
       <MvASSIGN NAME = "l.pos" VALUE = 1>
       <MvASSIGN NAME = "l.cookie" VALUE = "{ trim( gettoken( sessInfo, ';', l.pos ) ) }">
       <MvWHILE EXPR = "{ len( l.cookie ) }"> 
          <MvASSIGN NAME = "l.cookie_name" VALUE = "{ trim( gettoken( l.cookie, '=', 1 ) ) }">
          <MvASSIGN NAME = "l.cookie_value" VALUE = "{ trim( gettoken( l.cookie, '=', 2 ) ) }">
          <MvASSIGN NAME = "l.cookies" MEMBER = "{ l.cookie_name }" VALUE = "{ l.cookie_value }">
          <MvASSIGN NAME = "l.pos" VALUE = "{ l.pos + 1 }">
          <MvASSIGN NAME = "l.cookie" VALUE = "{ trim( gettoken( s.http_cookie, ';', l.pos ) ) }">
       </MvWHILE>
       <MvAssign name="theSess" value="{ gettoken(cookies:xxxxxx,'|',4) }">
       <MvAssign name="theToken" value="{ gettoken(cookies:xxxxxx,'|',3) }">
       <MvAssign name="somethingNew" value="{ gettoken(cookies:xxxxx,'|',2) }">
       <MvAssign name="isEnabled" value="{ gettoken(cookies:xxxxx,'|',1) }">
    </MvFunction>
    William Gilligan - Orange Marmalade, Inc.
    www.OrangeMarmaladeinc.com

    Comment

    • netblazon
      Developer Partner




      • Mar 2006
      • 717

      #3
      Bill, thanks for replying. I'm not entirely sure how I would use that function...for example, what do you pass in for sessInfo? But, that said, it looks like this might just parse cookies and not http headers. Tell me if I'm wrong about that!
      susan
      Susan Petracco
      NetBlazon

      1.866.400.2444

      _____________________________________________

      Like us on Facebook

      Comment

      • netblazon
        Developer Partner




        • Mar 2006
        • 717

        #4
        I'm looking for the MivaScript equivalent of PHP's getallheaders function.
        Susan Petracco
        NetBlazon

        1.866.400.2444

        _____________________________________________

        Like us on Facebook

        Comment

        • wmgilligan
          Developer Partner




          • Feb 2006
          • 742

          #5
          Sorry about that! I missed a part:
          Code:
             s.http_cookie
          William Gilligan - Orange Marmalade, Inc.
          www.OrangeMarmaladeinc.com

          Comment

          • wmgilligan
            Developer Partner




            • Feb 2006
            • 742

            #6
            This should cycle thru all the cookies. And I _think_ in the order they were entered.
            William Gilligan - Orange Marmalade, Inc.
            www.OrangeMarmaladeinc.com

            Comment

            • netblazon
              Developer Partner




              • Mar 2006
              • 717

              #7
              But it's not cookies I need. It's the HTTP headers.
              Susan Petracco
              NetBlazon

              1.866.400.2444

              _____________________________________________

              Like us on Facebook

              Comment

              • wmgilligan
                Developer Partner




                • Feb 2006
                • 742

                #8
                my bad - I knew I wasn't reading something right.
                I am 99% certain miva_output_flush will do this, and that I have done it - but I can't locate it in my code....
                I will keep looking...
                William Gilligan - Orange Marmalade, Inc.
                www.OrangeMarmaladeinc.com

                Comment

                • netblazon
                  Developer Partner




                  • Mar 2006
                  • 717

                  #9
                  I appreciate your help!
                  Susan Petracco
                  NetBlazon

                  1.866.400.2444

                  _____________________________________________

                  Like us on Facebook

                  Comment

                  • wmgilligan
                    Developer Partner




                    • Feb 2006
                    • 742

                    #10
                    Ok. I may be remembering something from a while ago..


                    I do recall though writing some code that grabbed everything and wrote it to a file....
                    I am hoping someone else can chime in...
                    William Gilligan - Orange Marmalade, Inc.
                    www.OrangeMarmaladeinc.com

                    Comment

                    • ILoveHostasaurus
                      Mega Mivite










                      • Mar 2006
                      • 4998

                      #11
                      There isn't a specific function for this, but if Empresa is running under CGI with a typical CGI handler having invoked it and set environment variables with the http headers, then those variables will have been auto assigned an equivalent s.http_NAME variable with the header. You could of course iterate over all the variables, but that wouldn't be the best for performance. You would not be able to determine the order in which the headers were sent because that information would not be sent to Empresa. I'm not sure if you'd be able to determine that at all unless you wrote a different handler for the web server you're using to attach an order of occurrence to the headers as they're passed to the application receiving the request.
                      David Hubbard
                      CIO
                      Miva
                      [email protected]
                      http://www.miva.com

                      Comment

                      • ILoveHostasaurus
                        Mega Mivite










                        • Mar 2006
                        • 4998

                        #12
                        Some additional info: http://www.mivascript.com/topic/system-variables.html
                        David Hubbard
                        CIO
                        Miva
                        [email protected]
                        http://www.miva.com

                        Comment

                        • netblazon
                          Developer Partner




                          • Mar 2006
                          • 717

                          #13
                          OK, got it, I'll see what I can hack together based on that. Thanks!
                          Susan Petracco
                          NetBlazon

                          1.866.400.2444

                          _____________________________________________

                          Like us on Facebook

                          Comment

                          • kayakbabe
                            Mega Mivite




                            • Jun 2008
                            • 1520

                            #14
                            an idea... I once sort did something sorta similar.
                            I used an incoming header to set a server var in htaccess. then I appended that to the query string again in htaccess. then I used that to set a global var.

                            would that work for you?

                            I also seem to remember something about apache level server vars being available within miva... but that was a long time ago as in maybe 2006ish... it's worth exploring.

                            Comment

                            Working...
                            X