Skip to content

Commit

Permalink
Fix proxy error
Browse files Browse the repository at this point in the history
  • Loading branch information
pkendall64 committed Sep 10, 2023
1 parent acbacf9 commit 7e5c920
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions mdns-proxy/proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ int connect_client(int conn, const char *dest)

if(inet_pton(AF_INET, dest, &serv_addr.sin_addr)<=0)
{
printf("inet_pton error occured\n");
printf("inet_pton error occurred\n");
return -1;
}

Expand Down Expand Up @@ -188,12 +188,14 @@ int process_response(int conn)
int peer = connection[conn].peer;
// forward data to peer
if (!connection[conn].started) {
// add in CORS header
const char *header = "\r\nAccess-Control-Allow-Origin: *";
const char *end = strstr(buffer, "\r\n\r\n");
if (output(peer, buffer, end - buffer) == -1) return -1;
if (output(peer, header, strlen(header)) == -1) return -1;
return output(peer, end, nbytes - (end - buffer));
// add in CORS header if theres not one already
if (strstr(buffer, "Access-Control-Allow-Origin:") == 0) {
const char *header = "\r\nAccess-Control-Allow-Origin: *";
const char *end = strstr(buffer, "\r\n\r\n");
if (output(peer, buffer, end - buffer) == -1) return -1;
if (output(peer, header, strlen(header)) == -1) return -1;
return output(peer, end, nbytes - (end - buffer));
}
}
return output(peer, buffer, nbytes);
}
Expand Down

0 comments on commit 7e5c920

Please sign in to comment.