Net/http get early hints (103)

I tried to check against: https://early-hints.fastlylabs.com
and want to get the 103 status code, or at least check if he is there, but 103 is of course not persistent and will be overwritten once the 200 was fired.
Is there a way of capturing the 103 code?

I tried this, but it just gave back the 200 (OK) code:

package main

import (
	"fmt"
	"log"
	"net/http"
)

func main() {
	resp, err := http.Head("https://early-hints.fastlylabs.com/")
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Println(resp.Status)
}

But it just returns:

200 OK

When I try:

package main

import (
	"fmt"
	"log"
	"net/http"
	"net/http/httputil"
)

func main() {
	resp, err := http.Head("https://early-hints.fastlylabs.com/")
	if err != nil {
		log.Fatalln(err)
	}

	b, err := httputil.DumpResponse(resp, false)
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Println(string(b))
}

I get a header like:

HTTP/2.0 200 OK
[...]

But never a Code 103 (EarlyHint).
Is there a way to get the 103 (if triggered) and store it before it turns into a 200 just like at cURL?

curl -X HEAD -I https://early-hints.fastlylabs.com/ 2>&1
HTTP/2 103
origin-trial: [#########]
link: </hinted.png>; rel=preload; as=image

HTTP/2 200
[...]

Here I see the 103 code, but I am not able to make golang (net/http) show it to me.
Maybe this function is missing, or just not possible yet, even tho they are defined here: http package - net/http - Go Packages

StatusEarlyHints = 103 // RFC 8297

I btw am on golang v1.19.1, so the very latest.

I haven’t tried this, but after reading net/http: unexpected 1XX status codes are not handled well · Issue #17739 · golang/go · GitHub and net/http: support for the 103 status code · Issue #51914 · golang/go · GitHub, it looks like you have to:

I expect you will receive callbacks into the function you registered with Got1xxResponse with the 103 respons(s).

1 Like

Thank you very much for your response! :slight_smile:

Yeah, I have seen this issue, but for me it appears this is solely about “sending” 103. I don’t want to send, actually just check if a 103 is there.

Wow, that sounds way more complex than I thought, but I will give it a try.
I will report back, once i tried it.

Yeah, I made it! Thank you for your super helpful reply!

Now I need to adjust it.