-
Notifications
You must be signed in to change notification settings - Fork 99
/
server_appengine.html
39 lines (33 loc) · 1.32 KB
/
server_appengine.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
---
layout: default
title: enable cross-origin resource sharing
---
<div class="container">
<section>
<h1>CORS on App Engine</h1>
<p>
For Python-based applications in Google <a href="http://code.google.com/appengine/">App Engine</a>, the <code>self.response.headers.add_header()</code> method can be used, such as:
</p>
<pre class="code">class CORSEnabledHandler(webapp.RequestHandler):
def get(self):
self.response.headers.add_header("Access-Control-Allow-Origin", "*")
self.response.headers['Content-Type'] = 'text/csv'
self.response.out.write(self.dump_csv())</pre>
<p>
For Java-based applications, use <code>resp.addHeader()</code>:
</p>
<pre class="code">public void doGet(HttpServletRequest req, HttpServletResponse resp) {
resp.addHeader("Access-Control-Allow-Origin", "*");
resp.addHeader("Content-Type", "text/csv");
resp.getWriter().append(csvString);
}</pre>
<p>
And for Go-based applications, use <code>w.Header().Add()</code>:
</p>
<pre class="code">func doGet(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Access-Control-Allow-Origin", "*")
w.Header().Add("Content-Type", "text/csv")
fmt.Fprintf(w, csvData)
}</pre>
</section>
</div>