BugFix related to uft8
This commit is contained in:
parent
2ca9ac7a1b
commit
40849e0fbb
13
main.go
13
main.go
|
@ -29,7 +29,11 @@ type StreamResponse struct {
|
|||
|
||||
const linux = "python3"
|
||||
|
||||
func createStreamResponse(fromLanguage, toLanguage, message string) string {
|
||||
func streamResponse(w http.ResponseWriter, fromLanguage, toLanguage string, messages <-chan string) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
w.Header().Set("Connection", "keep-alive")
|
||||
|
||||
response := StreamResponse{
|
||||
From: fromLanguage,
|
||||
To: toLanguage,
|
||||
|
@ -159,7 +163,7 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, "Request content type must be application/json", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
body, err := io.ReadAll(r.Body)
|
||||
body, err := io.ReadAll(io.NopCloser(io.Reader(r.Body)))
|
||||
if err != nil {
|
||||
http.Error(w, "Error reading request body: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -173,6 +177,11 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// Convert byte slices to strings
|
||||
msg.Message = string(body)
|
||||
msg.From = string(msg.From)
|
||||
msg.To = string(msg.To)
|
||||
|
||||
if len(msg.From) > 2 || len(msg.To) > 2 {
|
||||
http.Error(w, "From and To fields should not be longer than 2 letters.", http.StatusBadRequest)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue