How to add new HTTP Headers

MiServer is Dyalog's APL-based web development framework

How to add new HTTP Headers

Postby woody on Fri Jul 01, 2016 1:34 am

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
woody
 
Posts: 144
Joined: Tue Dec 28, 2010 12:54 am
Location: Atlanta, Georgia USA

Re: How to add new HTTP Headers

Postby MBaas on Fri Jul 01, 2016 9:44 am

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
MBaas
 
Posts: 156
Joined: Thu Oct 16, 2008 1:17 am
Location: Gründau / Germany

Re: How to add new HTTP Headers

Postby woody on Fri Jul 01, 2016 12:09 pm

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
woody
 
Posts: 144
Joined: Tue Dec 28, 2010 12:54 am
Location: Atlanta, Georgia USA

Re: How to add new HTTP Headers

Postby Brian|Dyalog on Fri Jul 01, 2016 1:18 pm

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
Brian|Dyalog
 
Posts: 116
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: How to add new HTTP Headers

Postby woody on Fri Jul 01, 2016 1:25 pm

Perfect!

Sincere thanks!
Woodley Butler
Automatonics, Inc.
"Find your head in the APL Cloud"
http://www.APLcloud.com
User avatar
woody
 
Posts: 144
Joined: Tue Dec 28, 2010 12:54 am
Location: Atlanta, Georgia USA


Return to MiServer

Who is online

Users browsing this forum: No registered users and 1 guest