get raw headers?

M

Mark

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.UrlReferrer, then skims
through the Uri.Query string looking at the name/value pairs.

It's doing a Server.UrlDecode() on both the name and value portions of the
pair, but UrlDecode() doesn't have an UrlDecode(string, 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
 
B

bruce barker

HttpUtility.UrlDecode supports a string, and string supports SubString, so it:

string s = HttpUtility.UrlDecode(header.SubString(iStart,iLen));

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

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


-- bruce (sqlwork.com)
 
S

Steven Cheng [MSFT]

Hi Mark,

As Bruce has suggested, you can use HttpUtility.UrlDecode(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.UrlReferrer 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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

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

--------------------
Thread-Topic: get raw headers?
thread-index: Aci5zgEa37thEtzOTsqUd05rnKujlQ==
X-WBNR-Posting-Host: 207.46.193.207
From: =?Utf-8?B?TWFyaw==?= <[email protected]>
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.UrlReferrer, then skims
through the Uri.Query string looking at the name/value pairs.

It's doing a Server.UrlDecode() on both the name and value portions of the
pair, but UrlDecode() doesn't have an UrlDecode(string, 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
 
M

Mark

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 said:
Hi Mark,

As Bruce has suggested, you can use HttpUtility.UrlDecode(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.UrlReferrer 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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

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

--------------------
Thread-Topic: get raw headers?
thread-index: Aci5zgEa37thEtzOTsqUd05rnKujlQ==
X-WBNR-Posting-Host: 207.46.193.207
From: =?Utf-8?B?TWFyaw==?= <[email protected]>
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.UrlReferrer, then skims
through the Uri.Query string looking at the name/value pairs.

It's doing a Server.UrlDecode() on both the name and value portions of the
pair, but UrlDecode() doesn't have an UrlDecode(string, 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
 
S

Steven Cheng [MSFT]

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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?TWFyaw==?= <[email protected]>
References: <[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top