r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!Cheyenne] Discussions about the Cheyenne Web Server

Dockimbel
30-Sep-2008
[2867x2]
PUT file : the tmp file is deleted once the HTTP response is sent 
back to client. If you want to keep the file, you need to either 
rename it (with its original name) or move it elsewhere.
It's a security feature to avoid saturating server's disk with unwanted 
files.
Graham
30-Sep-2008
[2869x2]
Ok, got it.
And my REST question?
Dockimbel
30-Sep-2008
[2871x9]
First you should avoid URI starting with /@ unless you've disabled 
mod-internal module.
Then if you want to process URI that do not map directly to the filesystem, 
you can either use ALIAS (untested) : ALIAS "/" %rest-dispatcher.rsp
(requires Cheyenne v0.9.19)
if you're doing that, you should define a dedicated virtual domain.
Other option (more powerful, but more complex), write a specific 
mod-rest module and if required, a background task handler. Not easy 
to do but could be done by copy/pasting code from mod-action/CGI 
or  mod-rsp/RSP and adapting to your needs.
OTOH, you could also make a more simpler mod-rest acting as a REST 
wrapper and just rewriting the URL to point to a simple ressource 
(CGI or RSP) and saving the REST url inside a custom HTTP header. 
That way, you could easily redirect a REST call to a RSP dispatcher. 
If you go that way, I would recommend to write a module with a single 
callback early in the Cheyenne's request processing pipeline.
Here's an untested skeleton code for such a mod-rest :
REBOL [ ]

install-HTTPd-extension [
	name: 'mod-rest
	
	order: [
		url-translate	first
	]
	
	parse-REST: func [url /local new][
		...
		do the REST url to RSP url conversion here
		...
		new
	]
	
	url-translate: func [req /local new][
		if not find/part req/in/url "/@" 2 [return none]
		
		;-- save URL in a custom header 
		h-store req/in/headers 'REST-url req/in/url
		
		;-- rewrite URL
		new: parse-REST req/in/url
		
		;-- refresh the req/in objet content
		service/parse-request-line/short new req/in
		
		true
	]
]
Don't forget also to add the REST module name to the MODULES section 
in %httpd.cfg file.
Graham
30-Sep-2008
[2880x6]
thanks.
I see that request/posted either contains a filename, or, binary 
data depending on the size of the binary data.
I was looking for a web to fax gateway last night and found one that 
was about 10Mb using ruby on rails and a REST interface.  Instructions 
were in English but it looked like I had to be conversant with ROR 
to configure it!
Here's my one page web to fax gateway for Hylafax http://www.compkarori.co.nz/showpost.php?p=36&postcount=14
 :)
Ok, I admit it doesn't do any of the other stuff that the RoR one 
does, as all it does is just send a fax.
and to send the fax from REBOL is just


response: read/custom url?faxno=113432423&recipient=Joe Bloggs&extension=.pdf 
[ PUT %mypdffax.pdf ]
Kaj
1-Oct-2008
[2886]
Good old Hylafax :-)
Graham
1-Oct-2008
[2887x3]
Linux question .. can I run cheyenne with iniittab or whatever?
I gather one day it might be possible to write a non-standard ftp 
hylafax protocol ... but in the meantime I guess I'm restricted to 
running the commandline utilities.
Can rebol read stdin ( eg. get the output from faxstat ) and then 
send it to a rsp page?
Dockimbel
1-Oct-2008
[2890]
stdin: try launching rebol with --cgi
Graham
1-Oct-2008
[2891]
so a rsp page can read stdin?
Dockimbel
1-Oct-2008
[2892]
I don"t see the point of a rsp page reading stdin ?
Graham
1-Oct-2008
[2893]
to get the output of a command line program
Dockimbel
1-Oct-2008
[2894x2]
inittab : sure, we're using it on our servers (but i'm not the linux 
guru here, so can't help you much with that).
Use call/output to read the output of a command line program launched 
from a REBOL session.
Graham
1-Oct-2008
[2896x2]
thanks
working ... http://compkarori.no-ip.biz:8001/faxstat.rsp
Graham
3-Oct-2008
[2898x3]
I want to allow download of the faxes.  I made the file  names links

<a href=showfax.rsp?fax000000.tif>fax000000.tif</a>

and showfax.rsp is 

<%
recvqdir: %/var/spool/hylafax/recvq/
file: dehex request/content/filename

switch suffix? file [
	%.tif [ response/set-header 'Content-type "image/tiff" ]
	%.pdf [ response/set-header 'Content-type "application/pdf" ]
]
response/buffer: read/binary join recvqdir file file
%>

but when the file downloads,it is called showfax.rsp ...
Anyone know how to set the name of the file being downloaded?
<a href=showfax.rsp?file=fax000000.tif>fax000000.tif</a>
Dockimbel
3-Oct-2008
[2901]
I guess that you need to add this : response/set-header 'Content-disposition 
"attachment; filename=fax000000.tif"
Terry
3-Oct-2008
[2902]
Hey Doc, Im using the embed version of Cheyenne, but I can't grab 
any files for downloading.. the dialog box opens, but the content 
is empty.. with this error in the console.. 
target: rockstar.rar

## Error in [uniserve] : On-received call failed with error: make 
object! [
    code: 312
    type: 'script
    id: 'cannot-use
    arg1: 'path
    arg2: 'none!
    arg3: none
    near: [either req/file-info/size > 16384 [
            req/out/content: req/in/file
        ]]
    where: 'handler
] !

Any ideas?
Graham
3-Oct-2008
[2903]
Thanks ... I'll try that out tomorrow.
Gabriele
3-Oct-2008
[2904]
Graham: content-disposition should work, but there may be browsers 
or other clients that ignore it. there is a trick that should always 
work though, but i don't know if Cheyenne supports it: use a url 
like this: showfax.rsp/fax000000.tif?otherargs - you probably won't 
need to put the file name after the ? because most servers (and i 
assume Cheyenne, if this is supported) give you access to the actual 
request path.
Graham
3-Oct-2008
[2905]
I can try it .... but I suspect I'll get  a 404
Terry
3-Oct-2008
[2906x3]
Doc, regarding the issue above, I'm not getting the error now, but 
the content is still corrupted? ie: if I read/binary a .zip file, 
set the header to application/x-zip-compressed, the browser is recognizing 
the file size, but the file itself is corrupted? Happens with all 
binary files.
Do you have an example i can use in the embed-demo.r file that returns 
a binary?
nvm.. the response was sending back a subsequent rebol error.
Graham
3-Oct-2008
[2909]
Content-disposition worked fine! :)
Terry
3-Oct-2008
[2910]
What's the best way to make the params using embed global so I can 
pass them on to subsequent functions?
Dockimbel
4-Oct-2008
[2911]
I don't understand the  "params using embed" part of your question.
Terry
4-Oct-2008
[2912x2]
yeah..  missing a comma.. 

What I meant was.. I'm using embed, and I want to pass the params 
object to other, non-cheyenne functions that I DO from the /default 
function
Scope issue (my Rebol is rusty)... what I did was copy the content 
->  qstr: make object! decode-cgi to-string req/in/content
and make my own object . Im guessing this is not ideal
Dockimbel
4-Oct-2008
[2914]
I still don't understand where's your issue...What's wrong with :

your-function: func [obj][
	;-- do whatever you want here with 'obj
]

publish-site [
	default: func [req params svc][
		your-function req
	]
	...
]
Terry
4-Oct-2008
[2915x2]
I've strayed from the path a bit.. I only have one function.. default.. 
then manage everything from there
but I see what you mean...   can the  [req params svc] args be accessed 
outside of the publish-site function?