Created
August 19, 2011 02:10
-
-
Save jasom/1155870 to your computer and use it in GitHub Desktop.
hack for x-forwarded-for
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
int connection_proxy_deliver(Connection *conn) | |
{ | |
int rc = 0; | |
int req_len = Request_header_length(conn->req); | |
int cont_len = Request_content_length(conn->req); | |
int total_len = req_len+cont_len; | |
bstring xff; | |
char *xffBuf; | |
unsigned sofar=0; | |
char *buf = IOBuf_read_all(conn->iob, total_len, CLIENT_READ_RETRIES); | |
check(buf != NULL, "Failed to read from the client socket to proxy."); | |
rc = IOBuf_send(conn->proxy_iob, IOBuf_start(conn->iob), req_len-2); | |
check(rc > 0, "Failed to send to proxy."); | |
xff = Request_get(conn->req, &HTTP_X_FORWARDED_FOR); | |
#error Don't copy and paste this, the Right Way is to use a filter | |
xffBuf = malloc(blength(&HTTP_X_FORWARDED_FOR)+2+blength(xff)+2); | |
memcpy(xffBuf,bdata(&HTTP_X_FORWARDED_FOR),blength(&HTTP_X_FORWARDED_FOR)); | |
sofar+=blength(&HTTP_X_FORWARDED_FOR); | |
memcpy(xffBuf+sofar,": ",2); | |
sofar+=2; | |
memcpy(xffBuf+sofar,bdata(xff),blength(xff)); | |
sofar+=blength(xff); | |
memcpy(xffBuf+sofar,"\r\n",2); | |
sofar+=2; | |
rc = IOBuf_send(conn->proxy_iob, xffBuf, sofar); | |
check(rc > 0, "Failed to send to proxy."); | |
rc = IOBuf_send(conn->proxy_iob, IOBuf_start(conn->iob)+req_len-2, cont_len+2); | |
check(rc > 0, "Failed to send to proxy."); | |
return REQ_SENT; | |
error: | |
return REMOTE_CLOSE; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment