Rebol/Core
在玩弄(278-3-1) 以制作一种网络服务器来提供静态文本时显然无法捕获的错误,其中包含指向新服务位置的重定向链接。
错误的具体位置似乎在Carl Sassenrath
他在 2006 年编写的示例代码中,所以我有点困惑,这么多年后可能会出现未检测到的错误。
我让其中三个脚本同时运行,监控三个单独的端口。本质上,该脚本可以正常工作...当一次使用多个浏览器(在所有并行脚本上)重复访问时,它似乎很稳定...但是一个接一个地失败了。有时在 2 分钟后,有时在 20 分钟后 - 在添加打印语句后有时甚至在 60 分钟后 - 但最终它们会像这样失败:
** 脚本错误:超出范围或结束
** 哪里:永远
** 附近:不是空的?请求:第一个 http 端口
我尝试将程序循环的几乎每个部分都包装在 try[][exception] 中,但错误仍然存在。不幸的是,每年的这个时候我的搜索功能似乎很弱,因为我没有找到任何可以解释这个问题的东西。
该代码是 Carl Sassenrath 的Tiny Web Server的精简版,稍作修改以绑定到特定 IP,并发出 HTML 而不是加载文件:
REBOL [title: "TestMovedServer"]
AppName: "Test"
NewSite: "http://test.myserver.org"
listen-port: open/lines tcp://:81 browse http://10.100.44.6?
buffer: make string! 1024 ; will auto-expand if needed
forever [
http-port: first wait listen-port
clear buffer
while [not empty? request: first http-port][
print request
repend buffer [request newline]
print "----------"
]
repend buffer ["Address: " http-port/host newline]
print buffer
Location: ""
mime: "text/html"
parse buffer ["get" ["http" | "/ " | copy Location to " "]]
data: rejoin [{
<HTML><HEAD><TITLE>Site Relocated</TITLE></HEAD>
<BODY><CENTER><BR><BR><BR><BR><BR><BR>
<H1>} AppName { have moved to <A HREF="} NewSite {">} NewSite {</A></H1>
<BR><BR><BR>Please update the link you came from.
<BR><BR><BR><BR><BR><A HREF="} NewSite Location {">(Continue directly to the requested page)</A>
</CENTER></BODY></HTML>
}]
insert data rejoin ["HTTP/1.0 200 OK^/Content-type: " mime "^/^/"]
write-io http-port data length? data
close http-port
print "============"
]
我很期待看到你们从中得到什么!