Skip to content

Commit

Permalink
Set no-cache header
Browse files Browse the repository at this point in the history
  • Loading branch information
zpao committed Mar 1, 2015
1 parent 3557139 commit 0894520
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ func handleComments(w http.ResponseWriter, r *http.Request) {
}

w.Header().Set("Content-Type", "application/json")
w.Header().Set("Cache-Control", "no-cache")
io.Copy(w, bytes.NewReader(commentData))

case "GET":
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Cache-Control", "no-cache")
// stream the contents of the file to the response
io.Copy(w, bytes.NewReader(commentData))

Expand Down
1 change: 1 addition & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ app.post('/comments.json', function(req, res) {
comments.push(req.body);
fs.writeFile('_comments.json', JSON.stringify(comments, null, 4), function(err) {
res.setHeader('Content-Type', 'application/json');
res.setHeader('Cache-Control', 'no-cache');
res.send(JSON.stringify(comments));
});
});
Expand Down
1 change: 1 addition & 0 deletions server.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function routeRequest()
file_put_contents('_comments.json', $comments);
}
header('Content-Type: application/json');
header('Cache-Control: no-cache');
echo $comments;
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def comments_handler():
with open('_comments.json', 'w') as file:
file.write(json.dumps(comments, indent=4, separators=(',', ': ')))

return Response(json.dumps(comments), mimetype='application/json')
return Response(json.dumps(comments), mimetype='application/json', headers={'Cache-Control': 'no-cache'})

if __name__ == '__main__':
app.run(port=3000)
1 change: 1 addition & 0 deletions server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

# always return json
res['Content-Type'] = 'application/json'
res['Cache-Control'] = 'no-cache'
res.body = JSON.generate(comments)
end

Expand Down

0 comments on commit 0894520

Please sign in to comment.