Browse Source

jtp: support lack of carriage return

Benton Edmondson 2 years ago
parent
commit
db9791a45a
2 changed files with 19 additions and 19 deletions
  1. 2 2
      jtp/jtp.go
  2. 17 17
      jtp/jtp_test.go

+ 2 - 2
jtp/jtp.go

@@ -188,7 +188,7 @@ func validateHeaders(buf *bufio.Reader) error {
 			return err
 		}
 
-		if line == "\r\n" {
+		if line == "\r\n" || line == "\n" {
 			break
 		}
 
@@ -221,7 +221,7 @@ func findLocation(buf *bufio.Reader, baseLink *url.URL) (*url.URL, error) {
 			return nil, err
 		}
 
-		if line == "\r\n" {
+		if line == "\r\n" || line == "\n" {
 			break
 		}
 

+ 17 - 17
jtp/jtp_test.go

@@ -3,9 +3,9 @@ package jtp
 import (
 	"testing"
 	"mimicry/util"
-	// "net/url"
-	// "encoding/json"
-	// "os"
+	"net/url"
+	"encoding/json"
+	"os"
 )
 
 func TestStatusLineNoInfo(t *testing.T) {
@@ -19,19 +19,19 @@ func TestStatusLineNoInfo(t *testing.T) {
 
 // TODO: put this behind an --online flag or figure out
 // how to nicely do offline tests
-// func TestBasic(t *testing.T) {
-// 	link, err := url.Parse("https://httpbin.org/redirect/20")
-// 	if err != nil {
-// 		panic(err)
-// 	}
+func TestBasic(t *testing.T) {
+	link, err := url.Parse("https://httpbin.org/redirect/20")
+	if err != nil {
+		panic(err)
+	}
 
-// 	dict, err := Get(link, 20)
-// 	if err != nil {
-// 		panic(err)
-// 	}
+	dict, err := Get(link, 20)
+	if err != nil {
+		panic(err)
+	}
 
-// 	err = json.NewEncoder(os.Stdout).Encode(dict)
-// 	if err != nil {
-// 		panic(err)
-// 	}
-// }
+	err = json.NewEncoder(os.Stdout).Encode(dict)
+	if err != nil {
+		panic(err)
+	}
+}