Skip to content

Commit

Permalink
Tweaks for Windows
Browse files Browse the repository at this point in the history
  * Improve error handling when something's already listening on the port
  * Fix make request newline handling
  • Loading branch information
pipeline committed Apr 15, 2024
1 parent f98d51a commit 4b80d89
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cmd/pakikicore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,11 @@ func crash(w http.ResponseWriter, r *http.Request) {
func createListener(portParameter int, hostname string) net.Listener {
listener, err := net.Listen("tcp4", hostname+":"+strconv.Itoa(portParameter))
if err != nil {
if strings.Contains(err.Error(), "address already in use") {
if strings.Contains(err.Error(), "address already in use") || strings.Contains(err.Error(), "Only one usage of each socket address") {
fmt.Printf("Error: Port %d is already in use, could not use it for the UI. Using a random one.\n", portParameter)
return createListener(0, hostname)
} else {
fmt.Fprintf(os.Stderr, "Error starting listener: %s", err)
panic(err)
}
}
Expand Down
7 changes: 6 additions & 1 deletion internal/proxy/make_requests_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,12 @@ func initConnectionPool() {
updateConnectionPool(defaultConnectionPool, nil)
}

func makeRequestToSite(ssl bool, hostname string, requestData []byte, httpClient *http.Client, httpContext context.Context) (*project.Request, error) {
func makeRequestToSite(ssl bool, hostname string, req []byte, httpClient *http.Client, httpContext context.Context) (*project.Request, error) {
requestData := req
if bytes.ContainsAny(req, "\r") && !bytes.ContainsAny(req, "\n") {
requestData = bytes.ReplaceAll(req, []byte("\r"), []byte("\n"))
}

blankReq := &project.Request{
URL: "",
Protocol: "HTTP",
Expand Down
3 changes: 1 addition & 2 deletions pkg/project/request_model_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"html"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -910,7 +909,7 @@ func highlightAndEncode(req []byte, shouldHighlight bool, maxHighlightLength int
// @Router /requests/highlight [post]
func HighlightRequest(w http.ResponseWriter, r *http.Request) {
// read the request body
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, "Could not read request body: "+err.Error(), http.StatusInternalServerError)
return
Expand Down

0 comments on commit 4b80d89

Please sign in to comment.