mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	REST API输出时增加application/json; charset=utf-8 Header
This commit is contained in:
		@@ -147,7 +147,7 @@ func (this *RestServer) handle(writer http.ResponseWriter, req *http.Request) {
 | 
				
			|||||||
	err = json.Unmarshal(body, reqValue)
 | 
						err = json.Unmarshal(body, reqValue)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		writer.WriteHeader(http.StatusBadRequest)
 | 
							writer.WriteHeader(http.StatusBadRequest)
 | 
				
			||||||
		_, _ = writer.Write([]byte(err.Error()))
 | 
							_, _ = writer.Write([]byte("Decode request failed: " + err.Error() + ". Request body should be a valid JSON data"))
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -187,13 +187,15 @@ func (this *RestServer) handle(writer http.ResponseWriter, req *http.Request) {
 | 
				
			|||||||
				"data":    maps.Map{},
 | 
									"data":    maps.Map{},
 | 
				
			||||||
			}, shouldPretty)
 | 
								}, shouldPretty)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
 | 
								writer.Header().Set("Content-Type", "application/json; charset=utf-8")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			_, _ = writer.Write(dataJSON)
 | 
								_, _ = writer.Write(dataJSON)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (this *RestServer) writeJSON(writer http.ResponseWriter, v maps.Map, pretty bool) {
 | 
					func (this *RestServer) writeJSON(writer http.ResponseWriter, v maps.Map, pretty bool) {
 | 
				
			||||||
	writer.Header().Set("Content-Type", "application/json")
 | 
						writer.Header().Set("Content-Type", "application/json; charset=utf-8")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if pretty {
 | 
						if pretty {
 | 
				
			||||||
		_, _ = writer.Write(v.AsPrettyJSON())
 | 
							_, _ = writer.Write(v.AsPrettyJSON())
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user