How to add new HTTP Headers

MiServer is Dyalog's APL-based web development framework
Post Reply
User avatar
woody
Posts: 146
Joined: Tue Dec 28, 2010 12:54 am
Location: Atlanta, Georgia USA
Contact:

How to add new HTTP Headers

Post by woody »

Greetings.

I would like to add a custom HTTP Header.

I see in the V2.0 manual, I can READ Headers req.GetHeader 'cookie' for example.

But, how do I create a new HEADER element.

Thanks!

//W
Woodley Butler
Automatonics, Inc.
"Find your head in the APL Cloud"
http://www.APLcloud.com
User avatar
MBaas
Posts: 156
Joined: Thu Oct 16, 2008 1:17 am
Location: Gründau / Germany
Contact:

Re: How to add new HTTP Headers

Post by MBaas »

Hi Woodley,

I hope the following sample (execute after loading MiServer and starting any page) gives you some inspiration ;-)

Code: Select all

      xx←⎕NEW #.MiPage
      xx.Head.Add _.meta'' 'foo=goo'
      +xx.Render
<!DOCTYPE html><html><head><meta foo="goo"/></head><body></body></html>


BTW, that first (empty) argument is the content of the meta-tag (as applies to all atags):

Code: Select all

      ((⎕New #.MiPage).Head.Add _.meta'Hello world' 'foo=goo').Render
<meta foo="goo">Hello world</meta>
User avatar
woody
Posts: 146
Joined: Tue Dec 28, 2010 12:54 am
Location: Atlanta, Georgia USA
Contact:

Re: How to add new HTTP Headers

Post by woody »

Thanks!

Yes.. These HTML headers <HEAD> are very interesting.

I am also interested in the HTTP Headers.

I would like to ADD a new HTTP Header 'miserver-instance' with some value like 'APLcloud;Server.1234;DyalogAPL.v14.1;MiServer.v2.0;Port.8004'

This is what I see now:

HTTPHeaders.JPG


Thoughts?

Thanks!
Woodley Butler
Automatonics, Inc.
"Find your head in the APL Cloud"
http://www.APLcloud.com
User avatar
Brian|Dyalog
Posts: 120
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: How to add new HTTP Headers

Post by Brian|Dyalog »

Hi Woodley!

The headers you displayed are from the HTTP request from the client.
The headers you want to set in MiServer are in the HTTP response.

Assuming your HTTPRequest object is stored in a variable called 'req' (as shown in your example), the response headers are stored in req.Response.Headers.

So, if wanted to set the 'miserver-instance' header you described...

In MiServer 2, you can set it directly, as in:
      req.Response.Headers⍪←'miserver-instance' 'APLcloud;Server.1234;DyalogAPL.v14.1;MiServer.v2.0;Port.8004'


Whereas in MiServer 3, we've added a SetHeader method to the HTTPRequest class:
      'miserver-instance' req.SetHeader 'APLcloud;Server.1234;DyalogAPL.v14.1;MiServer.v2.0;Port.8004'


I hope this helps!
/Brian
User avatar
woody
Posts: 146
Joined: Tue Dec 28, 2010 12:54 am
Location: Atlanta, Georgia USA
Contact:

Re: How to add new HTTP Headers

Post by woody »

Perfect!

Sincere thanks!
Woodley Butler
Automatonics, Inc.
"Find your head in the APL Cloud"
http://www.APLcloud.com
Post Reply