Skip to content

Commit

Permalink
Added .txt file type detection. Support for gzip and compress Content…
Browse files Browse the repository at this point in the history
…-Encoding. Need to add the same for Transfer-Encoding to complete issue lparenteau#2.
  • Loading branch information
lparenteau committed Apr 18, 2012
1 parent 5956be9 commit 28dfd29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions r/httpm.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,20 @@
set ^httpm("ct",".html")="text/html"
set ^httpm("ct",".css")="text/css"
set ^httpm("ct",".xml")="text/xml"
set ^httpm("ct",".txt")="text/plain"
set ^httpm("ct",".js")="application/javascript"
set ^httpm("ct",".jpg")="image/jpeg"
set ^httpm("ct",".jpeg")="image/jpeg"
set ^httpm("ct",".gif")="image/gif"
set ^httpm("ct",".png")="image/png"

;
set ^httpm("compressible","text/html")=""
set ^httpm("compressible","text/css")=""
set ^httpm("compressible","text/xml")=""
set ^httpm("compressible","text/plain")=""
set ^httpm("compressible","application/javascript")=""

quit

envconf()
Expand Down
21 changes: 17 additions & 4 deletions r/response.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@
if connection("httpver")="HTTP/1.1" write "Transfer-Encoding: chunked",eol if 1
else write "Content-Length: ",$zpiece(length,$char(9),1),eol

; Let the client know which compression will be used, if any.
if $data(request("ACCEPT-ENCODING")) do
. ; Send Vary header
. write "Vary: Accept-Encoding"_eol
. if $data(^httpm("compressible",ct)) do
. . set:request("ACCEPT-ENCODING")["compress" response("encoding")="compress"
. . set:request("ACCEPT-ENCODING")["gzip" response("encoding")="gzip"
. . write:$data(response("encoding")) "Content-Encoding: "_response("encoding")_eol

; Send Expires header
set expdate=$zpiece(curdate,",",1)+1_","_$zpiece(curdate,",",2)
write "Expires: "_$zdate(expdate,"DAY, DD MON YEAR 24:60:SS ")_"GMT"_eol
Expand Down Expand Up @@ -107,13 +116,17 @@ write connection("httpver")_" "_status_" "_^httpm("status",status)_eol
write "Server: "_conf("serverstring")_eol
quit

sendfile(file)
sendfile(filename)
;
; Read all content of a file and send it.
; Read all content of a file and send it. If compression was advertised, compress the file before sending it.
;
new old
new old,line,file
set old=$IO
open file:(fixed:wrap:readonly:chset="M")
if $data(response("encoding")) do
. set file="cmd"
. open file:(command=response("encoding")_" -c "_filename:fixed:wrap:readonly)::"PIPE"
. if 1
else set file=filename open file:(fixed:wrap:readonly:chset="M")
for use file read line:timeout quit:'$test quit:$zeof do
. use old
. write:connection("httpver")="HTTP/1.1" $$FUNC^%DH($zlength(line),1),eol
Expand Down

0 comments on commit 28dfd29

Please sign in to comment.