Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Set no-cache header #37

Merged
merged 1 commit into from
Mar 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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