I have a specific case where I need to parse HTTP/2 response output into Go's http.Response. Response itself has default structure:
$ curl --include https://google.com
HTTP/2 301
location: https://www.google.com/
content-type: text/html; charset=UTF-8
date: Mon, 15 Jun 2020 11:08:39 GMT
expires: Wed, 15 Jul 2020 11:08:39 GMT
cache-control: public, max-age=2592000
server: gws
content-length: 220
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>
Status and body itself doesn't matter, it's just an example.
http library has function ReadResponse(r *bufio.Reader, req *Request) (*Response, error) which does exactly what I need, but it fails parsing HTTP/2 with malformed HTTP version HTTP/2, however it works fine for HTTP/1.1 and HTTP/1.0. Also, after doing request with http.DefaultClient.Do() you can see that response's field Proto contains HTTP/2.0, which means that there is no problem with HTTP/2.
Any ideas how to parse this response?
HTTP/2.replaceHTTP/2toHTTP/1.1orHTTP/2.0.HTTP/2.0as well, butHTTP/1.1does the trick, won't simply replacing version break something in more complex responses?HTTP/2, and then replace the first 7 bytes.