File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
compiler/natives/net/http Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 8
8
"errors"
9
9
"io/ioutil"
10
10
"net/textproto"
11
+ "strconv"
11
12
12
13
"github.com/gopherjs/gopherjs/js"
13
14
)
@@ -38,11 +39,22 @@ func (t *XHRTransport) RoundTrip(req *Request) (*Response, error) {
38
39
xhr .Set ("onload" , func () {
39
40
header , _ := textproto .NewReader (bufio .NewReader (bytes .NewReader ([]byte (xhr .Call ("getAllResponseHeaders" ).String () + "\n " )))).ReadMIMEHeader ()
40
41
body := js .Global .Get ("Uint8Array" ).New (xhr .Get ("response" )).Interface ().([]byte )
42
+
43
+ contentLength := int64 (- 1 )
44
+ if req .Method == "HEAD" {
45
+ i , err := strconv .ParseInt (header .Get ("Content-Length" ), 10 , 64 )
46
+ if err == nil {
47
+ contentLength = i
48
+ }
49
+ } else {
50
+ contentLength = int64 (len (body ))
51
+ }
52
+
41
53
respCh <- & Response {
42
54
Status : xhr .Get ("status" ).String () + " " + xhr .Get ("statusText" ).String (),
43
55
StatusCode : xhr .Get ("status" ).Int (),
44
56
Header : Header (header ),
45
- ContentLength : int64 ( len ( body )) ,
57
+ ContentLength : contentLength ,
46
58
Body : ioutil .NopCloser (bytes .NewReader (body )),
47
59
Request : req ,
48
60
}
You can’t perform that action at this time.
0 commit comments