Skip to content

Commit 8493392

Browse files
committed
Fix invalid HTTP/1.1
1 parent ce66e83 commit 8493392

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

package/src/synoedit/http_response.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ type HTTPResponse struct {
3434
func NewHTTPResponse(statusCode int, statusMessage string) *HTTPResponse {
3535
HTTPResponse := HTTPResponse{
3636
statusCode: statusCode,
37-
Status: "Status: " + fmt.Sprintf("%v", statusCode) + " " + statusMessage + "\n",
38-
ContentType: "Content-Type: text/html; charset=utf-8\n",
37+
Status: "Status: " + fmt.Sprintf("%v", statusCode) + " " + statusMessage + "\r\n",
38+
ContentType: "Content-Type: text/html; charset=utf-8\r\n",
3939
}
4040
return &HTTPResponse
4141
}
4242

4343
// Print http response to stdout
4444
func (HTTPResponse *HTTPResponse) print(str ...string) {
45-
fmt.Println(HTTPResponse.Status + HTTPResponse.ContentType)
45+
fmt.Print(HTTPResponse.Status + HTTPResponse.ContentType + "\r\n\r\n")
4646
fmt.Println(strings.Join(str, " "))
4747
os.Exit(0)
4848
}

package/src/synoedit/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func renderHTML(fileData string, successMessage string, errorMessage string) {
7272
page.Applications = config.Applications
7373
page.ErrorMessage = errorMessage
7474
page.SuccessMessage = successMessage
75-
fmt.Println("Status: 200 OK\nContent-Type: text/html; charset=utf-8\nServer: synoedit", AppVersion)
76-
fmt.Println()
75+
fmt.Print("Status: 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nServer: synoedit", AppVersion)
76+
fmt.Print("\r\n\r\n")
7777
err = tmpl.Execute(os.Stdout, page)
7878
if err != nil {
7979
logError(err.Error())
@@ -146,8 +146,8 @@ func main() {
146146
output := ExecuteAction(appName)
147147

148148
if ajax == "true" {
149-
fmt.Println("Status: 200 OK\nContent-Type: text/plain;\n")
150-
fmt.Println(output)
149+
fmt.Print("Status: 200 OK\r\nContent-Type: text/plain;\r\n\r\n")
150+
fmt.Print(output)
151151
return
152152
}
153153
renderHTML(fileData, "Not implemented", "")
@@ -159,8 +159,8 @@ func main() {
159159
SaveFile(filePath, fileData)
160160

161161
if ajax == "true" {
162-
fmt.Println("Status: 200 OK\nContent-Type: text/plain;\n")
163-
fmt.Println("File saved successfully!")
162+
fmt.Print("Status: 200 OK\r\nContent-Type: text/plain;\r\n\r\n")
163+
fmt.Print("File saved successfully!")
164164
return
165165
}
166166
renderHTML(fileData, "File saved successfully!", "") // not complete
@@ -180,8 +180,8 @@ func main() {
180180

181181
if ajax := readGet().Get("ajax"); ajax == "true" {
182182
// expect an ajax response
183-
fmt.Println("Status: 200 OK\nContent-Type: text/plain;\n")
184-
fmt.Println(fileData)
183+
fmt.Print("Status: 200 OK\r\nContent-Type: text/plain;\r\n\r\n")
184+
fmt.Print(fileData)
185185
return
186186
}
187187
// else respond with full html

package/ui/js/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function ajax (method, data, successFunc) {
6969
var request = new XMLHttpRequest()
7070
request.onload = function() {
7171
if (request.status >= 200 && request.status < 400) {
72+
debug('ajax response', request)
7273
successFunc(request)
7374
} else {
7475
console.error(request.status, request.responseText)
@@ -144,7 +145,6 @@ appSelector.addEventListener('change', function(e) {
144145
fileSelector.addEventListener('change', function(e) {
145146
var param = addParameter('app', appSelector.value) + addParameter('file', e.target.value)
146147
ajax('GET', param, function(r) {
147-
debug('response', r)
148148
if (typeof editor !== 'undefined') {
149149
editor.getDoc().setValue(r.responseText)
150150
} else {

0 commit comments

Comments
 (0)