Last active
October 21, 2017 19:00
-
-
Save cgt/bd14b8250eac6a7dc8a9830f5bb0bf85 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"net/url" | |
) | |
func request(url_ string) { | |
req, err := http.NewRequest("HEAD", url_, nil) | |
if err != nil { | |
panic(err) | |
} | |
res, err := http.DefaultClient.Do(req) | |
if err != nil { | |
panic(err) | |
} | |
res.Body.Close() | |
fmt.Println(url_, res.Status) | |
} | |
func main() { | |
okURL, err := url.Parse("https://www.gkogan.co/blog/dont-design-emails/") | |
if err != nil { | |
panic(err) | |
} | |
badURL, err := url.Parse("https://www.gkogan.co/blog/dont-design-emails") | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("OK URL:\n%#v\n\n", okURL) | |
fmt.Printf("Bad URL:\n%#v\n\n", badURL) | |
request(okURL.String()) | |
request(badURL.String()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go run h2nilderef.go master | |
OK URL: | |
&url.URL{Scheme:"https", Opaque:"", User:(*url.Userinfo)(nil), Host:"www.gkogan.co", Path:"/blog/dont-design-emails/", RawPath:"", ForceQuery:false, RawQuery:"", Fragment:""} | |
Bad URL: | |
&url.URL{Scheme:"https", Opaque:"", User:(*url.Userinfo)(nil), Host:"www.gkogan.co", Path:"/blog/dont-design-emails", RawPath:"", ForceQuery:false, RawQuery:"", Fragment:""} | |
https://www.gkogan.co/blog/dont-design-emails/ 200 OK | |
panic: runtime error: invalid memory address or nil pointer dereference | |
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x5bafc0] | |
goroutine 35 [running]: | |
net/http.(*http2pipe).Write(0xc4200ba168, 0xc4204ca000, 0x29, 0x87, 0x0, 0x0, 0x0) | |
/opt/go/src/net/http/h2_bundle.go:3661 +0x100 | |
net/http.(*http2clientConnReadLoop).processData(0xc4204c9fb0, 0xc42007ce70, 0xc42007ce70, 0x0) | |
/opt/go/src/net/http/h2_bundle.go:8259 +0x2ac | |
net/http.(*http2clientConnReadLoop).run(0xc4204c9fb0, 0x67ec80, 0xc420461fb0) | |
/opt/go/src/net/http/h2_bundle.go:7896 +0x54f | |
net/http.(*http2ClientConn).readLoop(0xc42007eb60) | |
/opt/go/src/net/http/h2_bundle.go:7788 +0x9d | |
created by net/http.(*http2Transport).newClientConn | |
/opt/go/src/net/http/h2_bundle.go:7053 +0x6b9 | |
panic: runtime error: invalid memory address or nil pointer dereference | |
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x5df730] | |
goroutine 1 [running]: | |
net/http.(*http2ClientConn).RoundTrip.func1(0x0, 0x0, 0x0, 0x0, 0x18, 0x0) | |
/opt/go/src/net/http/h2_bundle.go:7324 +0x240 | |
net/http.(*http2ClientConn).RoundTrip(0xc42007eb60, 0xc420122000, 0x0, 0x0, 0x0) | |
/opt/go/src/net/http/h2_bundle.go:7356 +0xe80 | |
net/http.(*http2Transport).RoundTripOpt(0xc420084230, 0xc420122000, 0xc42014c100, 0xc420053848, 0x40a860, 0xffffffffffffffff) | |
/opt/go/src/net/http/h2_bundle.go:6858 +0x145 | |
net/http.(*http2Transport).RoundTrip(0xc420084230, 0xc420122000, 0x592601, 0xc420016120, 0xc420053a78) | |
/opt/go/src/net/http/h2_bundle.go:6820 +0x3a | |
net/http.http2noDialH2RoundTripper.RoundTrip(0xc420084230, 0xc420122000, 0xc4203bc360, 0x5, 0xc420098aa8) | |
/opt/go/src/net/http/h2_bundle.go:990 +0x39 | |
net/http.(*Transport).RoundTrip(0x7b6420, 0xc420122000, 0x7b6420, 0x0, 0x0) | |
/opt/go/src/net/http/transport.go:371 +0xd47 | |
net/http.send(0xc420122000, 0x784c20, 0x7b6420, 0x0, 0x0, 0x0, 0xc4202400c0, 0x7d9738, 0x7848e0, 0x2) | |
/opt/go/src/net/http/client.go:249 +0x1a9 | |
net/http.(*Client).send(0x7b9ee0, 0xc420122000, 0x0, 0x0, 0x0, 0xc4202400c0, 0x1, 0x2, 0x0) | |
/opt/go/src/net/http/client.go:173 +0xfd | |
net/http.(*Client).Do(0x7b9ee0, 0xc420102200, 0xc4203bc360, 0x2d, 0x0) | |
/opt/go/src/net/http/client.go:602 +0x28d | |
main.request(0xc4203bc360, 0x2d) | |
/home/cgt/dev/go/src/h2nilderef/h2nilderef.go:14 +0xaf | |
main.main() | |
/home/cgt/dev/go/src/h2nilderef/h2nilderef.go:37 +0x1a1 | |
exit status 2 | |
$ go run h2nilderef.go 1 master | |
OK URL: | |
&url.URL{Scheme:"https", Opaque:"", User:(*url.Userinfo)(nil), Host:"www.gkogan.co", Path:"/blog/dont-design-emails/", RawPath:"", ForceQuery:false, RawQuery:"", Fragment:""} | |
Bad URL: | |
&url.URL{Scheme:"https", Opaque:"", User:(*url.Userinfo)(nil), Host:"www.gkogan.co", Path:"/blog/dont-design-emails", RawPath:"", ForceQuery:false, RawQuery:"", Fragment:""} | |
https://www.gkogan.co/blog/dont-design-emails/ 200 OK | |
panic: runtime error: invalid memory address or nil pointer dereference | |
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x5bafc0] | |
goroutine 35 [running]: | |
net/http.(*http2pipe).Write(0xc4203962a8, 0xc4203f8000, 0x29, 0x87, 0x0, 0x0, 0x0) | |
/opt/go/src/net/http/h2_bundle.go:3661 +0x100 | |
net/http.(*http2clientConnReadLoop).processData(0xc4203f7fb0, 0xc42049a360, 0xc42049a360, 0x0) | |
/opt/go/src/net/http/h2_bundle.go:8259 +0x2ac | |
net/http.(*http2clientConnReadLoop).run(0xc4203f7fb0, 0x67ec80, 0xc4204967b0) | |
/opt/go/src/net/http/h2_bundle.go:7896 +0x54f | |
net/http.(*http2ClientConn).readLoop(0xc42007eb60) | |
/opt/go/src/net/http/h2_bundle.go:7788 +0x9d | |
created by net/http.(*http2Transport).newClientConn | |
/opt/go/src/net/http/h2_bundle.go:7053 +0x6b9 | |
exit status 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment