-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
uoosef
committed
Sep 3, 2023
1 parent
9f2378c
commit 49d519c
Showing
3 changed files
with
400 additions
and
212 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package server | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
// ParseHTTPHost parses the head of the first HTTP request on conn and returns | ||
// a new, unread connection with metadata for virtual host muxing | ||
func ParseHTTPHost(rd io.Reader) (string, error) { | ||
var request *http.Request | ||
var err error | ||
if request, err = http.ReadRequest(bufio.NewReader(rd)); err != nil { | ||
return "", err | ||
} | ||
|
||
// You probably don't need access to the request body and this makes the API | ||
// simpler by allowing you to call Free() optionally | ||
defer func(Body io.ReadCloser) { | ||
err := Body.Close() | ||
if err != nil { | ||
|
||
} | ||
}(request.Body) | ||
|
||
return request.Host, nil | ||
} |
This file contains 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
Oops, something went wrong.