我使用rack-webdav gem在rails应用程序中创建了一个webdav服务器。
我在Rails应用程序中使用Rack基本身份验证。
使用libre office时,我可以1.在文件浏览器中查看文件,2.打开文件,3.编辑并4.上传文件。
使用不带机架基本身份验证的ms word时,我可以1.在文件浏览器中查看文件,2.打开文件,3.编辑并4.上传文件。
使用带机架基本身份验证的ms word时,我只能执行1.在文件浏览器中查看文件。
当尝试通过机架基本身份验证以ms字格式打开文件时,将向服务器发出Profind请求,并返回400错误请求。我在propfind方法中添加了一个绑定撬,它不会停止执行代码,这意味着它永远不会碰到控制器方法。我知道当请求中不包含身份验证时,Rack基本身份验证会抛出400错误的请求。
这是我在Windows 10中设置webdav并复制问题的方法:
在Windows中访问我的计算机目录
右键单击网络,然后单击地图网络驱动器
在“文件夹”字段中,输入webdav服务器信息,进行身份验证并单击“完成”
打开ms单词,单击文件并浏览
导航到网络驱动器
我在网络驱动器目录中看到文件
会导致propfind请求,该请求引发400错误的请求错误。服务器具有SSL,所以我不认为这是问题所在。
任何帮助将不胜感激
我尝试通过“连接到可用于存储文档和图片的网站”选项从Windows 10设置与webdav服务器的连接,但这不允许我从Windows 10的Webdav服务器中查看文件。 ms word文件浏览器(当您单击从ms word内部浏览时)。
# my custom webdav controller
class WebDavController < RackWebDAV::Controller
def initialize(request, response, options)
@request = request
@response = response
@options = options
@resource = resource_class.new(url_unescape(request.path_info), @request, @response, @options)
raise Forbidden if request.path_info.include?('../')
end
# this method is used to populate which file are available in the word document editor
# which is connecting to webdav server
# Note: this function should only return one file as users can only check out one file at a time
# and users can only view files which they have checked out.
def propfind
token = request.url.split("?token=")[1]
#raise NotFound if not resource.exist?
if not request_match("/d:propfind/d:allprop").empty?
nodes = all_prop_nodes
else
nodes = request_match("/d:propfind/d:prop/*")
nodes = all_prop_nodes if nodes.empty?
end
nodes.each do |n|
# Don't allow empty namespace declarations
# See litmus props test 3
raise BadRequest if n.namespace.nil? && n.namespace_definitions.empty?
# Set a blank namespace if one is included in the request
# See litmus props test 16
# <propfind xmlns="DAV:"><prop><nonamespace xmlns=""/></prop></propfind>
if n.namespace.nil?
nd = n.namespace_definitions.first
if nd.prefix.nil? && nd.href.empty?
n.add_namespace(nil, '')
end
end
end
multistatus do |xml|
for resource in find_resources
resource.path.gsub!(/\/\//, '/')
# do not show file to word document editor unless the file is checked out by logged in user
# "/."
# "/"
if resource.path != "/." and resource.path != "/"
if resource.file_locked? @options[:user_id]
# we do nothing here
else
next
end
end
# if "next" was not executed in the previous block, we allow the
# file to be visible within the file explorer when being accessed
# via web dav
xml.response do
xml.href "http://#{host}#{@request.script_name}#{url_escape resource.path}"
propstats xml, get_properties(resource, nodes)
end
end
end
end
# sends a file to the word document editor via webdav
def get
raise NotFound if not resource.exist?
response['Etag'] = resource.etag
response['Content-Type'] = resource.content_type
response['Content-Length'] = resource.content_length.to_s
response['Last-Modified'] = resource.last_modified.httpdate
map_exceptions do
resource.get @options[:user_id]
end
end
def put
map_exceptions do
resource.put
end
response.status = Created
response['Location'] = "#{request.scheme}://#{request.host}:#{request.port}#{url_format_for_response(resource)}"
end
def head
raise NotFound if not resource.exist?
response['Etag'] = resource.etag
response['Content-Type'] = resource.content_type
response['Content-Length'] = resource.content_length.to_s
response['Last-Modified'] = resource.last_modified.httpdate
end
def lock
response.status = 200
end
def unlock
response.status = 200
end
def options
response["Allow"] = 'OPTIONS,HEAD,GET,PUT,POST,DELETE,PROPFIND,PROPPATCH,MKCOL,COPY,MOVE'
response["Dav"] = "1"
if resource.exist?
response["Allow"] << ",LOCK,UNLOCK"
response["Dav"] << ",2"
end
response["Ms-Author-Via"] = "DAV"
end
end
实际上没有错误,当我通过ngrok创建到开发服务器和生产服务器的隧道时,我只看到400 Bad Request。