Gargoyle 有自己的網頁伺服器,改良自 mini_httpd。
source reference: httpd_gargoyle.c
主程式呼叫 handle_request()
- 從 socket 讀取 HTTP header
- 每次最多讀 10000 bytes,直到有兩個換行
- ssl or not
- parse request line
- method, url, protocol
- method: GET, HEAD, POST
- url: with '?' for query
- parse all other headers,包括 Authorization:、Content-Length:等
- url: decode, remove ../, virtual host
- 檔案不存在處理
- 目錄:如有 defaultPageFile 或 index 檔,則依照檔案方式處理;不然則 list directory
- 檔案:不能是禁止取用的檔案,如果符合 CGI 檔格式 (由設定檔 cgipat 參數或指令行 -c 參數設定) 則執行它,不然直接傳送檔案
- 執行 CGI 檔
- 必須是 GET 或 POST
- 建立環境變數 envp
- 建立執行參數 argp
- stdin, stdout, stderr 導到 socket,中間可能插入另一個 process
- execve(CGI 檔, argp, envp)
沒有留言:
張貼留言