git.s-ol.nu json-hopper / 7f92365
fix headers s-ol 1 year, 2 months ago
3 changed file(s) with 27 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
00 {
1 "RefererPattern": "^https://localhost($|/)",
2 "RedirectTemplate": "https://localhost/form?id={{.Id}}&key={{.Key}}"
1 "RefererPattern": "^http://localhost:8000/",
2 "RedirectTemplate": "http://localhost:8000/form?id={{.Id}}&key={{.Key}}"
33 }
88 "description": "The person's first name.",
99 "format": "email"
1010 },
11 "ages": {
11 "contents": {
1212 "type": "array",
1313 "items": {
14 "type": "integer",
15 "minimum": 0
14 "type": "string",
15 "enum": [
16 "keycaps",
17 "0xC.pad",
18 "0x33.board",
19 "midi",
20 "hid"
21 ]
1622 }
1723 },
18 "firstName": {
24 "frequency": {
1925 "type": "string",
20 "description": "The person's first name."
21 },
22 "lastName": {
23 "type": "string",
24 "description": "The person's last name."
26 "enum": [
27 "release",
28 "rare"
29 ]
2530 }
2631 },
2732 "additionalProperties": false,
28 "minProperties": 1
33 "minProperties": 2
2934 }
111111 }
112112
113113 func (h *SiteHandler) collectData(r *http.Request) (map[string]interface{}, error) {
114 err := r.ParseMultipartForm(0)
114 content_type := r.Header.Get("Content-Type")
115 var err error
116 if content_type == "application/x-www-form-urlencoded" {
117 err = r.ParseForm()
118 } else if content_type == "multipart/form-data" {
119 err = r.ParseMultipartForm(1 * 1024 * 1024)
120 }
115121 if err != nil {
116122 return nil, &HTTPError{http.StatusBadRequest, err}
117123 }
189195
190196 w.Header().Set("Content-Type", "application/json")
191197 w.Header().Set("Location", redirect_buf.String())
192 w.WriteHeader(http.StatusCreated)
198 w.WriteHeader(http.StatusSeeOther)
193199 w.Write(raw_data)
194200 return nil
195201 }
252258 case *HTTPError:
253259 code = e.code
254260 if e.root != nil {
255 log.Printf("Error: %#v", err)
261 log.Printf("Error %s: ", err.Error(), e.root)
256262 }
257263 default:
258264 code = http.StatusInternalServerError
259 log.Printf("Error: %#v", err)
265 log.Printf("Error: ", err)
260266 }
261267
262268 http.Error(w, http.StatusText(code), code)