Skip to content

Commit

Permalink
Fixed error when requesting /news/posts/ with no post id; now redirec…
Browse files Browse the repository at this point in the history
…t to /news/archive/.
  • Loading branch information
lparenteau committed Nov 9, 2012
1 parent f8d4442 commit 74d524f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion r/auth.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
;

; Support GET, HEAD, PUT, and POST methods
quit:'$$methodis^request("GET,HEAD,PUT,POST")
quit:'$$methodis^request("GET,HEAD,PUT,POST",1)

; If the connection is not secure, redirect to get a secure connection
if '$$issecure^connection() do quit
Expand Down
2 changes: 1 addition & 1 deletion r/databallet.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ set conf("compressible","text/plain")=1
set conf("compressible","application/javascript")=1

; DataBallet version : YYYYMMDD
set databalletver=20121105
set databalletver=20121108

quit

Expand Down
11 changes: 7 additions & 4 deletions r/news.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
new localvar

; Support GET and HEAD methods
quit:'$$methodis^request("GET,HEAD,PUT,POST")
quit:'$$methodis^request("GET,HEAD,PUT,POST",1)

; Default urlroot
if '$data(urlroot) new urlroot set urlroot="/"
Expand All @@ -50,7 +50,7 @@
else if request("uri")=(urlroot_"archive/") do archive(docroot,urlroot) if 1
else if request("uri")=(urlroot_"admin/") do admin(docroot,urlroot) if 1
else if $zextract(request("uri"),1,$zlength(urlroot_"admin/"))=(urlroot_"admin/") do adminaction(docroot,urlroot) if 1
else if $zextract(request("uri"),1,$zlength(urlroot_"posts/"))=(urlroot_"posts/") do post(docroot) if 1
else if $zextract(request("uri"),1,$zlength(urlroot_"posts/"))=(urlroot_"posts/") do post(docroot,urlroot) if 1
; Everything else is 404 Not Found.
else do set^response(404) quit

Expand Down Expand Up @@ -180,14 +180,17 @@ set response("headers","Content-Type")="text/html"

quit

post(docroot)
post(docroot,urlroot)
;
; Handle specific post
;
new lastmod,postid

set postid=$zpiece(request("uri"),"/",4,4)
if '$data(@NEWS@("post",postid)) do set^response(405) quit
; Redirect to archive if no post requested
if postid="" do set^response(301) set response("headers","Location")=urlroot_"archive/" quit
; 404 if requested post does not exist
if '$data(@NEWS@("post",postid)) do set^response(404) quit
; Use template engine to load the header of the page. Convention is to use '<docroot>/start.html', which can include a <title>{%}title{%}</title> line in there
; to make use of @NEWS@("title")
set localvar("title")=$get(@NEWS@("title"))_" | "_@NEWS@("post",postid,"title")
Expand Down
8 changes: 4 additions & 4 deletions r/request.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

quit

methodis(methods)
methodis(methods,setstatus)
;
; Compare current request's method with the comma seperated list of methods.
;
Expand All @@ -62,15 +62,15 @@
; Method is in the supplied list
quit:p'="" 1
; Method is not in the supplied list
do set^response(405)
do:$data(setstatus) set^response(405)
quit 0

validatecache()
;
; Validate the cachem, based on request and response.
; Validate the cache, based on request and response.
;
new status
set status=200
set status=$get(response("status"),200)

; It is never valid if the client request no-cache.
if $get(request("headers","CACHE-CONTROL"))'="no-cache" do
Expand Down
2 changes: 1 addition & 1 deletion r/static.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
;

; Support GET and HEAD methods
quit:'$$methodis^request("GET,HEAD")
quit:'$$methodis^request("GET,HEAD",1)

; Get the path + file name. An appropriate HTTP error message will be set if the file isn't found.
if '$data(urlroot) new urlroot set urlroot="/"
Expand Down
2 changes: 1 addition & 1 deletion r/template.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
;

; Support GET and HEAD methods
quit:'$$methodis^request("GET,HEAD")
quit:'$$methodis^request("GET,HEAD",1)

; Templates are pretty much handled like static file, so use static's getfile to
; get the full file + pathname to the requested element. An appropriate HTTP error
Expand Down

0 comments on commit 74d524f

Please sign in to comment.