--web共有で.css、.js、.html/htmファイルのヘッダを強制的に「text/css」「text/javascript」「text/html」として送り出すスクリプト。旧名put_css。 --web共有の「アクション」に「拡張子で開く」で登録して使う。 --MIME設定からはcss、js、html、htmを削除しておく必要がある。 --ver21 2006/9/26 --・ファイルの最終更新日を正しく送り返していないバグを修正 --ver2 2006/9/22 --・このバージョンからTanaka's OSAXが必須となった。2.01推奨。 --・名前をresheadに変更。 --・リクエストヘッダ「If-Modified-Since」を解析し、ファイルに変更がなければ「304 Not modified」を返すようにした。 --・レスポンスヘッダに「Date」「Last-Modified」を追加。 --ver1.01 2005/12/15 html/htmもサポート。どちらも「text/html」として出力する。これはiCab対策。 --ver1.0 2005/10/5 最初のバージョン property debug : "" --通常空にする。1でファイルを送るたびにbeep。2で詳細表示。 property crlf : (ASCII character 13) & (ASCII character 10) property head200css : "HTTP/1.1 200 OK" & crlf & "Content-Type: text/css" & crlf property head200js : "HTTP/1.0 200 OK" & crlf & "Content-Type: text/javascript" & crlf property head200html : "HTTP/1.0 200 OK" & crlf & "Content-Type: text/html" & crlf property head304notmod : "HTTP/1.0 304 Not Modified" & crlf & crlf property rootDir : "" on run --- 起動時に、rootDir に Web のルートのパスを収める set rootDir to (":" as alias) as string end run on handle CGI request myPathArg executing by myPath with full request reqhead --myPath リクエストされたファイルのパス --reqhead UAからの全リクエスト内容 -- リクエストされたcss(myPath)をファイルのパス(myFilePath)に変換 set myFilePath to my barasu(myPath, "/", 1) --/で分解 set myFilePath to my barasu(myFilePath, ":", 0) --:でつなぐ(置換する) set reqFilePath to rootDir & myFilePath --このままだと例えば HD_name:web_page::aaa.css などとなって::が重なってしまう。 set reqFilePath to my barasu(reqFilePath, "::", 1) --::で分解 set reqFilePath to my barasu(reqFilePath, ":", 0) --:でつなぐ(置換する) --リクエストされたファイルの更新日時を取得。Tanaka's OSAX必要 try set fileMod to MT Get Info reqFilePath about modification_date on error --取得できなかった。たぶんファイルがない。なにもせずにサーバの処理に任せる return "" end try try --リクエストから最終更新日を取り出す。Tanaka's OSAX必要 set reqLMdate to item 1 of (MT Pick Strings reqhead start with "If-Modified-Since: " end with " GMT" with trimming) on error set reqLMdate to "" end try --リクエストの最終更新日を日付型に変換 set reqLMdate to my getLastMod(reqLMdate) if debug = "2" then --詳細表示 set UAreq to head200html & crlf & crlf & "============= request from UA =============" & return & "
filepath " & (myPath as text) & return & "
all req : " & return & (reqhead as text) & "req last mod : " & return & reqLMdate & return & "============= request from UA end =============" & return else set UAreq to "" end if --最終更新日のチェック if reqLMdate < fileMod then --ファイルの方が新しい --reqLMdateが空の場合(リクエストの中に更新日時がない)もこちらにくる if debug = "1" then beep --beep try --- ファイルを読み込む set myData to my readFile(reqFilePath) set resFileDate to (MT Convert Date (fileMod - (time to GMT)) to Header string) & " GMT" --ファイルの日付をレスポンスヘッダに変換 set resNowDate to (MT Convert Date ((current date) - (time to GMT)) to Header string) & " GMT" --ファイルの日付をレスポンスヘッダに変換 set suffix to my barasu(reqFilePath, ".", 1) --.で分解 if item -1 of suffix = "css" then --最期の項目がcssなら return UAreq & head200css & "Date: " & resNowDate & crlf & "Last-modified: " & resFileDate & crlf & crlf & myData else if item -1 of suffix = "js" then --最期の項目がjsなら return UAreq & head200js & "Date: " & resNowDate & crlf & "Last-modified: " & resFileDate & crlf & crlf & myData else --html/htmのはず return UAreq & head200html & "Date: " & resNowDate & crlf & "Last-modified: " & resFileDate & crlf & crlf & myData end if end if on error --たぶんファイルがなかった。なにもせずにサーバの処理に任せる return "" end try else --キャッシュと同じかファイルの方が古い return head304notmod --変更なしというコードを返す end if end handle CGI request --リクエストヘッダの日付を日付型に変換する -- set xxxx to my getLastMod(リクエストヘッダの日付) で呼び出す on getLastMod(reqLMdate) try --まずTanaka's OSAXで日付に変換してみる set reqLMdate to MT Convert Date reqLMdate to date on error --Tanaka's OSAXでは、月が例えば「Nov」なら変換できるが「NOV」では変換できない set theList to my barasu(reqLMdate, " ", 1) --スペースで分解 --月を数字に変換。出典 http://homepage1.nifty.com/ton_b/tips/Date/MonthWeek.html try set theMonth to ((offset of (item 3 of theList as text) in "JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBEROCTOBER NOVEMBER DECEMBER") + 8) / 9 set thisDate to item 4 of theList & "年 " & (theMonth as integer) & "月 " & item 2 of theList & "日 " & item 5 of theList --組み立て set reqLMdate to date thisDate --日付型に変換 on error --これでも取得できなければ空で戻す set reqLMdate to "" end try end try return reqLMdate end getLastMod on barasu(myText, newDel, bORt) --1は分解それ以外はつなぐ set oldDel to AppleScript's text item delimiters --デリミタを保存しておく set AppleScript's text item delimiters to newDel --渡されたデリミタにする if bORt = 1 then set myText to every text item of myText --1なら分解 else set myText to myText as string --それ以外はつなぐ end if set AppleScript's text item delimiters to oldDel --デリミタを元に戻す return myText end barasu --ファイルを読み込む on readFile(filePath) --該当ファイルを読み込む set filePath to filePath as string open for access file filePath --with write permission --ファイルを開く set txtData to read file filePath --ファイルを読む close access file filePath --ファイルを閉じる return txtData end readFile