0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WebDAV クライアントの User-agent を調べる

Posted at

WebDAVクライアントはいろいろ相性問題があるようで、ある特定のWebDAVサーバーできちんと利用できるWebDAVクライアントのホワイトリストまたはブラックリストを作る必要が出てきた。

そこで、クライアントのUser-agentを手っ取り早く調べる方法

https://gist.github.com/phrawzty/62540f146ee5e74ea1ab で、http.server.SimpleHTTPRequestHandler に少し手を加える、という方法が紹介されていた。これを真似して以下の通り。

BaseHTTPRequestHandler (SimpleHTTPRequestHandlerの親クラス)は do_メソッド という関数名で、HTTPリクエストメソッドへの応答を書くことができる。また該当するメソッドが実装されていないとその旨をコンソールメッセージとして返してくる。

import http.server
import logging
import argparse

class GetHandler(http.server.SimpleHTTPRequestHandler):
    def do_GET(self):
        print(self.headers)
        SimpleHTTPRequestHandler.do_GET(self)

    def do_PROPFIND(self):
        print(self.headers)

# copy from http.server
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--bind', '-b', default='', metavar='ADDRESS',
                        help='Specify alternate bind address '
                             '[default: all interfaces]')
    parser.add_argument('port', action='store',
                        default=8000, type=int,
                        nargs='?',
                        help='Specify alternate port [default: 8000]')
    args = parser.parse_args()
    handler_class = GetHandler
    http.server.test(HandlerClass=handler_class, port=args.port, bind=args.bind)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?