Page 1 of 1
How to add new HTTP Headers
Posted: Fri Jul 01, 2016 1:34 am
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
Re: How to add new HTTP Headers
Posted: Fri Jul 01, 2016 9:44 am
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>
Re: How to add new HTTP Headers
Posted: Fri Jul 01, 2016 12:09 pm
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:
Thoughts?
Thanks!
Re: How to add new HTTP Headers
Posted: Fri Jul 01, 2016 1:18 pm
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
Re: How to add new HTTP Headers
Posted: Fri Jul 01, 2016 1:25 pm
by woody
Perfect!
Sincere thanks!