char *HTTP_Request(URL *Url,Header *request_head,Body *request_body) { char *msg=NULL,*head; /* Make the request OK for a proxy or not. */ if(proxyUrl) MakeRequestProxyAuthorised(proxyUrl,request_head); else MakeRequestNonProxy(Url,request_head); /* Send the request. */ head=HeaderString(request_head); if(proxyUrl) PrintMessage(ExtraDebug,"Outgoing Request Head (to proxy)\n%s",head); else PrintMessage(ExtraDebug,"Outgoing Request Head (to server)\n%s",head); if(write_string(server,head)==-1) msg=GetPrintMessage(Warning,"Failed to write head to remote HTTP %s; [%!s].",proxyUrl?"proxy":"server"); if(request_body) if(write_data(server,request_body->content,request_body->length)==-1) msg=GetPrintMessage(Warning,"Failed to write body to remote HTTP %s; [%!s].",proxyUrl?"proxy":"server"); free(head); return(msg); }
char *HTTP_Request(Connection *connection,URL *Url,Header *request_head,Body *request_body) { char *msg=NULL,*head; size_t headlen; URL *proxyUrl=connection->proxyUrl; /* Make the request OK for a proxy or not. */ if(proxyUrl) MakeRequestProxyAuthorised(proxyUrl,request_head); else MakeRequestNonProxy(Url,request_head); /* Send the request. */ head=HeaderString(request_head,&headlen); if(proxyUrl) PrintMessage(ExtraDebug,"Outgoing Request Head (to proxy)\n%s",head); else PrintMessage(ExtraDebug,"Outgoing Request Head (to server)\n%s",head); if(write_data(connection->fd,head,headlen)<0) msg=GetPrintMessage(Warning,"Failed to write head to remote HTTP %s; [%!s].",proxyUrl?"proxy":"server"); else if(request_body && write_data(connection->fd,request_body->content,request_body->length)<0) msg=GetPrintMessage(Warning,"Failed to write body to remote HTTP %s; [%!s].",proxyUrl?"proxy":"server"); free(head); return(msg); }
char *SSL_Request(int client,URL *Url,Header *request_head) { char *msg=NULL; if(proxyUrl) { char *head; size_t headlen; ModifyRequest(Url,request_head); MakeRequestProxyAuthorised(proxyUrl,request_head); ChangeURLInHeader(request_head,Url->hostport); head=HeaderString(request_head,&headlen); PrintMessage(ExtraDebug,"Outgoing Request Head (to https (SSL) proxy)\n%s",head); if(write_data(server,head,headlen)<0) msg=GetPrintMessage(Warning,"Failed to write to remote https (SSL) proxy; [%!s]."); free(head); } else out_err=write_string(client,"HTTP/1.0 200 WWWOFFLE SSL OK\r\n\r\n"); return(msg); }
char *SSL_Open(URL *Url) { char *msg=NULL; char *proxy=NULL,*sproxy=NULL; int socksremotedns=0; socksdata_t *socksdata=NULL,socksbuf; /* Sort out the host. */ if(!IsLocalNetHost(Url->host)) { proxy=ConfigStringURL(SSLProxy,Url); sproxy=ConfigStringURL(SocksProxy,Url); socksremotedns=ConfigBooleanURL(SocksRemoteDNS,Url); } if(proxyUrl) { FreeURL(proxyUrl); proxyUrl=NULL; } if(proxy) Url=proxyUrl=CreateURL("http",proxy,"/",NULL,NULL,NULL); /* Open the connection. */ server=-1; if(Url->portnum) { if((sproxy && !(socksdata= MakeSocksData(sproxy,socksremotedns,&socksbuf))) || (server=OpenUrlSocket(Url,socksdata))==-1) { msg=GetPrintMessage(Warning,"Cannot open the https (SSL) connection to %s port %d; [%!s].",Url->host,Url->portnum); } else { init_io(server); configure_io_timeout_rw(server,ConfigInteger(SocketTimeout)); } } else msg=GetPrintMessage(Warning,"No port given for the https (SSL) connection to %s.",Url->host); return(msg); }
char *HTTP_Open(URL *Url) { char *msg=NULL; char *proxy=NULL; char *server_host=NULL; int server_port=-1; /* Sort out the host. */ if(!IsLocalNetHost(Url->host)) proxy=ConfigStringURL(Proxies,Url); if(proxy) { if(proxyUrl) FreeURL(proxyUrl); proxyUrl=NULL; proxyUrl=CreateURL("http",proxy,"/",NULL,NULL,NULL); server_host=proxyUrl->host; server_port=proxyUrl->port; } else { server_host=Url->host; server_port=Url->port; } if(server_port==-1) server_port=DefaultPort(Url); /* Open the connection. */ server=OpenClientSocket(server_host,server_port); if(server==-1) msg=GetPrintMessage(Warning,"Cannot open the HTTP connection to %s port %d; [%!s].",server_host,server_port); else { init_io(server); configure_io_timeout(server,ConfigInteger(SocketTimeout),ConfigInteger(SocketTimeout)); } return(msg); }