Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I pass custom data in the HTTP header?

Tags:

I have a whole bunch of web services each with several web methods. The consumers of these services are varied and many. I want to augment each of these web methods with an extra optional parameter (Int64 or Int32) but adding new methods with this extra (optional parameter) is a lot of work and getting the clients to use the new methods will be even more time consuming.

So I was wondering if I could allow the clients that wanted to take advantage of the new feature that this param provides could pass this Int in the HTTP header or some other way.

So the first question is can I pass an int in the HTTP header? If so, how would one do that in C#/ASP.NET?

Otherwise, what other suggestions do you have for tackling this problem?

like image 640
Guy Avatar asked Feb 18 '09 22:02

Guy


People also ask

How do you pass custom headers?

In order to pass custom HTTP Headers, you have to build a message using custom HTTP Headers. This is achieved by using MIME Service. Below code snippet (bpml) sets the custom headers and then build the MIME document using MIME Service and then assign the MIME document to PrimaryDocument.

Can we send data in header?

While request header can not contain actual data as mentioned above, you can use request header to send some specific header and based on that you can apply your logic. For instance, while creating a REST API you can send AUTHENTICATION header to verify if request is coming from an allowed user or not.

Can HTTP headers be custom?

There are many uses for custom headers and they are quite commonly used. Even if you aren't using a CDN or haven't specifically defined any custom HTTP headers on your origin server, you may still be sending responses with custom headers.

What kind of data is passed through HTTP headers?

The HTTP headers are used to pass additional information between the clients and the server through the request and response header. All the headers are case-insensitive, headers fields are separated by colon, key-value pairs in clear-text string format.


2 Answers

Its a bit unorthodox and I'm sure some purists would be upset at the idea (the headers should only be used for the transport of the message, and should not contain the semantics of the message).

Practically its doable, but you want to be sure all your clients can add these headers. If your clients are using tools to call the web methods rather than generating the HTTP requests themselves (which I'd hope is the case) then there's a real chance this is a problem.

Why is it so hard to add these additional overloads of the methods?

like image 149
Frank Schwieterman Avatar answered Oct 01 '22 11:10

Frank Schwieterman


Yes it is allowed - but note that it may cut off the ability to use proxies and sometimes http aware firewalls (they tend to inspect and rewrite headers).

like image 21
Michael Neale Avatar answered Oct 01 '22 11:10

Michael Neale