Skip to content

Commit

Permalink
panic safe type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
h0x0er committed Nov 13, 2023
1 parent 1662a67 commit 025907a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tohttp.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package http2util

import (
"fmt"
"net/http"

"golang.org/x/net/http2"
)

// Frame2HTTPRequest
func FrameToHTTPRequest(f *http2.MetaHeadersFrame) (*http.Request, error) {
// Frame2HTTPRequest creates http.Request from frame
func FrameToHTTPRequest(frame http2.Frame) (*http.Request, error) {
f, ok := frame.(*http2.MetaHeadersFrame)
if !ok {
return nil, fmt.Errorf("error: only http2.MetaHeadersFrame is supported")
}
return processMetaHeadersForRequest(f)
}

func FrameToHTTPResponse(f *http2.MetaHeadersFrame) (*http.Response, error) {
// FrameToHTTPResponse creates http.Response from frame
func FrameToHTTPResponse(frame http2.Frame) (*http.Response, error) {
f, ok := frame.(*http2.MetaHeadersFrame)
if !ok {
return nil, fmt.Errorf("error: only http2.MetaHeadersFrame is supported")
}
return processMetaHeadersForResponse(f)
}

0 comments on commit 025907a

Please sign in to comment.