get raw headers?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TWFyaw==?=

    get raw headers?

    Is there any easy way to get the raw headers (byte[])?

    We've got a routine that wants to check the referrer for certain query
    string parameters. At the moment, it gets Request.UrlRefe rrer, then skims
    through the Uri.Query string looking at the name/value pairs.

    It's doing a Server.UrlDecod e() on both the name and value portions of the
    pair, but UrlDecode() doesn't have an UrlDecode(strin g, start, len) overload
    - just an UrlDecode(byte[], start, len, encoding) one.

    In general, I was poking around the docs and didn't see any obvious way of
    getting the raw bytes of a given header. Is there such a thing?

    Thanks
    Mark

  • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

    #2
    RE: get raw headers?

    HttpUtility.Url Decode supports a string, and string supports SubString, so it:

    string s = HttpUtility.Url Decode(header.S ubString(iStart ,iLen));

    though it woudl be simple to spilt and decode (air code)

    var values = new Dictionary<stri ng,string>();
    foreach (string s in header.Split('& '))
    {
    var items = s.Split('=');
    if (items.Length 1)
    {
    values.Add(item s[0],HttpUtility.Ur lDecode(items[1]));
    }
    }


    -- bruce (sqlwork.com)


    "Mark" wrote:
    Is there any easy way to get the raw headers (byte[])?
    >
    We've got a routine that wants to check the referrer for certain query
    string parameters. At the moment, it gets Request.UrlRefe rrer, then skims
    through the Uri.Query string looking at the name/value pairs.
    >
    It's doing a Server.UrlDecod e() on both the name and value portions of the
    pair, but UrlDecode() doesn't have an UrlDecode(strin g, start, len) overload
    - just an UrlDecode(byte[], start, len, encoding) one.
    >
    In general, I was poking around the docs and didn't see any obvious way of
    getting the raw bytes of a given header. Is there such a thing?
    >
    Thanks
    Mark
    >

    Comment

    • Steven Cheng [MSFT]

      #3
      RE: get raw headers?

      Hi Mark,

      As Bruce has suggested, you can use HttpUtility.Url Decode(string) overload
      to decode the substring from the original UrlReferer path.

      As for raw header, it seems ASP.NET hasn't exposed the underlying binary
      data. So far you can access the UrlReferer via Request.UrlRefe rrer property
      or manually lookup the Request.Headers collection(as a string value).

      Is there any other concerns that you need accessing the raw bytes?

      Sincerely,

      Steven Cheng

      Microsoft MSDN Online Support Lead


      Delighting our customers is our #1 priority. We welcome your comments and
      suggestions about how we can improve the support we provide to you. Please
      feel free to let my manager know what you think of the level of service
      provided. You can send feedback directly to my manager at:
      msdnmg@microsof t.com.

      =============== =============== =============== =====
      Get notification to my posts through email? Please refer to
      Gain technical skills through documentation and training, earn certifications and connect with the community

      ications.

      =============== =============== =============== =====
      This posting is provided "AS IS" with no warranties, and confers no rights.

      --------------------
      >Thread-Topic: get raw headers?
      >thread-index: Aci5zgEa37thEtz OTsqUd05rnKujlQ ==
      >X-WBNR-Posting-Host: 207.46.193.207
      >From: =?Utf-8?B?TWFyaw==?= <mmodrall@nospa m.nospam>
      >Subject: get raw headers?
      >Date: Mon, 19 May 2008 09:33:01 -0700
      >
      >Is there any easy way to get the raw headers (byte[])?
      >
      >We've got a routine that wants to check the referrer for certain query
      >string parameters. At the moment, it gets Request.UrlRefe rrer, then skims
      >through the Uri.Query string looking at the name/value pairs.
      >
      >It's doing a Server.UrlDecod e() on both the name and value portions of the
      >pair, but UrlDecode() doesn't have an UrlDecode(strin g, start, len)
      overload
      >- just an UrlDecode(byte[], start, len, encoding) one.
      >
      >In general, I was poking around the docs and didn't see any obvious way of
      >getting the raw bytes of a given header. Is there such a thing?
      >
      >Thanks
      >Mark
      >
      >

      Comment

      • =?Utf-8?B?TWFyaw==?=

        #4
        RE: get raw headers?

        Hi Bruce, Steven...

        Several Microsoft whitepapers on performance optimization for .net say to
        steer clear of comparatively wasteful operations like String.Split() for all
        the extra objects they create putting burden on the garbage collector. I had
        a 1.1 app for reading log files that used Split a lot, and I found with
        Perfmon that it was spending 35-45% of the time in garbage collection. I
        re-implemented to avoid .Split() and performance improved about 30%.

        UrlDecode() had a ranged overload but only for the raw bytes, which seems
        kind of odd given how awkward it is to *get* raw bytes of anything you'd want
        to UrlDecode().

        Thanks
        Mark

        "Steven Cheng [MSFT]" wrote:
        Hi Mark,
        >
        As Bruce has suggested, you can use HttpUtility.Url Decode(string) overload
        to decode the substring from the original UrlReferer path.
        >
        As for raw header, it seems ASP.NET hasn't exposed the underlying binary
        data. So far you can access the UrlReferer via Request.UrlRefe rrer property
        or manually lookup the Request.Headers collection(as a string value).
        >
        Is there any other concerns that you need accessing the raw bytes?
        >
        Sincerely,
        >
        Steven Cheng
        >
        Microsoft MSDN Online Support Lead
        >
        >
        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msdnmg@microsof t.com.
        >
        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        Gain technical skills through documentation and training, earn certifications and connect with the community

        ications.
        >
        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no rights.
        >
        --------------------
        Thread-Topic: get raw headers?
        thread-index: Aci5zgEa37thEtz OTsqUd05rnKujlQ ==
        X-WBNR-Posting-Host: 207.46.193.207
        From: =?Utf-8?B?TWFyaw==?= <mmodrall@nospa m.nospam>
        Subject: get raw headers?
        Date: Mon, 19 May 2008 09:33:01 -0700
        >

        Is there any easy way to get the raw headers (byte[])?

        We've got a routine that wants to check the referrer for certain query
        string parameters. At the moment, it gets Request.UrlRefe rrer, then skims
        through the Uri.Query string looking at the name/value pairs.

        It's doing a Server.UrlDecod e() on both the name and value portions of the
        pair, but UrlDecode() doesn't have an UrlDecode(strin g, start, len)
        overload
        - just an UrlDecode(byte[], start, len, encoding) one.

        In general, I was poking around the docs and didn't see any obvious way of
        getting the raw bytes of a given header. Is there such a thing?

        Thanks
        Mark
        >
        >

        Comment

        • Steven Cheng [MSFT]

          #5
          RE: get raw headers?

          Thanks for the reply Mark,

          Yes, the UrlDecode method is not quite useful for those already
          encapsulated string values (from raw bytes) in asp.net. However, the
          UrlDecode(like many other encoding/decoding methods) belong to the
          HttpUtility class which is not restricted to be used in ASP.NET application
          only. You can also use it to do UrlEncode/Decode in your own application
          which may need to convert some raw byte array to string format encoded
          array. For example, if you're writing own http components that may need
          such utility function.

          Sincerely,

          Steven Cheng

          Microsoft MSDN Online Support Lead


          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msdnmg@microsof t.com.

          =============== =============== =============== =====
          Get notification to my posts through email? Please refer to
          Gain technical skills through documentation and training, earn certifications and connect with the community

          ications.

          =============== =============== =============== =====
          This posting is provided "AS IS" with no warranties, and confers no rights.
          --------------------
          >From: =?Utf-8?B?TWFyaw==?= <mmodrall@nospa m.nospam>
          >References: <6F937A57-E486-4126-87D9-B563DDD4261F@mi crosoft.com>
          <GEcinIjuIHA.45 12@TK2MSFTNGHUB 02.phx.gbl>
          >Subject: RE: get raw headers?
          >Date: Tue, 20 May 2008 07:11:01 -0700
          >
          >Hi Bruce, Steven...
          >
          >Several Microsoft whitepapers on performance optimization for .net say to
          >steer clear of comparatively wasteful operations like String.Split() for
          all
          >the extra objects they create putting burden on the garbage collector. I
          had
          >a 1.1 app for reading log files that used Split a lot, and I found with
          >Perfmon that it was spending 35-45% of the time in garbage collection. I
          >re-implemented to avoid .Split() and performance improved about 30%.
          >
          >UrlDecode() had a ranged overload but only for the raw bytes, which seems
          >kind of odd given how awkward it is to *get* raw bytes of anything you'd
          want
          >to UrlDecode().
          >
          >Thanks
          >Mark
          >
          >"Steven Cheng [MSFT]" wrote:
          >
          >Hi Mark,
          >>

          Comment

          Working...