26 #ifndef CURL_DISABLE_HTTP
33 #include <sys/types.h>
38 #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
42 #ifdef HAVE_SYS_SOCKET_H
43 #include <sys/socket.h>
45 #ifdef HAVE_NETINET_IN_H
46 #include <netinet/in.h>
51 #ifdef TIME_WITH_SYS_TIME
60 #ifdef HAVE_ARPA_INET_H
61 #include <arpa/inet.h>
66 #include <sys/ioctl.h>
69 #ifdef HAVE_SYS_PARAM_H
70 #include <sys/param.h>
73 #ifdef HAVE_SYS_SELECT_H
74 #include <sys/select.h>
97 #define _MPRINTF_REPLACE
114 size_t thislen = strlen(thisheader);
130 &authorization) > 0) {
150 &authorization) > 0) {
153 aprintf(
"Proxy-authorization: Basic %s\015\012", authorization);
241 !checkheaders(data,
"Proxy-authorization:")) {
242 auth=(
char *)
"Basic";
243 result = Curl_output_basic_proxy(conn);
251 infof(data,
"Proxy auth using %s with user '%s'\n",
259 data->
state.negotiate.context &&
260 !GSS_ERROR(data->
state.negotiate.status)) {
261 auth=(
char *)
"GSS-Negotiate";
262 result = Curl_output_negotiate(conn);
281 auth=(
char *)
"Digest";
283 (
unsigned char *)request,
284 (
unsigned char *)path);
291 !checkheaders(data,
"Authorization:")) {
292 auth=(
char *)
"Basic";
293 result = Curl_output_basic(conn);
302 infof(data,
"Server auth using %s with user '%s'\n",
331 if (httpcode == 407) {
332 start = header+strlen(
"Proxy-authenticate:");
336 start = header+strlen(
"WWW-Authenticate:");
349 while(*start && isspace((
int)*start))
367 int neg = Curl_input_negotiate(conn, start);
389 infof(data,
"Authentication problem. Ignoring this.\n");
404 infof(data,
"Authentication problem. Ignoring this.\n");
432 infof(data,
"Authentication problem. Ignoring this.\n");
443 static size_t readmoredata(
char *
buffer,
450 size_t fullsize = size * nitems;
480 memcpy(buffer, http->
postdata, fullsize);
563 res =
Curl_write(conn, sockfd, ptr, sendsize, &amount);
571 *bytes_written += amount;
573 if((
size_t)amount != size) {
580 ptr = in->
buffer + amount;
619 s = vaprintf(fmt, ap);
623 CURLcode result = add_buffer(in, s, strlen(s));
649 new_rb = (
char *)realloc(in->
buffer, new_size);
652 new_rb = (
char *)malloc(new_size);
686 size_t hlen = strlen(header);
696 start = &headerline[hlen];
699 while(*start && isspace((
int)*start))
703 end = strchr(start,
'\r');
706 end = strchr(start,
'\n');
710 end = strchr(start,
'\0');
714 clen = strlen(content);
717 for(;len>=clen;len--, start++) {
756 #define SELECT_ERROR 1
757 #define SELECT_TIMEOUT 2
760 infof(data,
"Establish HTTP proxy tunnel to %s:%d\n", hostname, remote_port);
774 host_port = aprintf(
"%s:%d", hostname, remote_port);
779 result = http_auth_headers(conn, (
char *)
"CONNECT", host_port, &auth);
785 "CONNECT %s:%d HTTP/1.0\015\012"
789 hostname, remote_port,
795 failf(data,
"Failed sending CONNECT to proxy");
802 FD_SET (tunnelsocket, &readfd);
815 while((nread<
BUFSIZE) && (keepon && !error)) {
825 failf(data,
"Proxy connection aborted due to timeout");
831 switch (
select (tunnelsocket+1, &readfd,
NULL,
NULL, &interval)) {
834 failf(data,
"Proxy CONNECT aborted due to select() error");
850 else if(gotbytes <= 0) {
853 failf(data,
"Proxy CONNECT aborted");
868 for(i = 0; i < gotbytes; ptr++, i++) {
880 if(data->
set.http_include_header)
891 if((
'\r' == line_start[0]) ||
892 (
'\n' == line_start[0])) {
899 letter = line_start[perline];
900 line_start[perline]=0;
901 if((
checkprefix(
"WWW-Authenticate:", line_start) &&
902 (401 == httpcode)) ||
904 (407 == httpcode))) {
909 else if(2 == sscanf(line_start,
"HTTP/1.%d %d",
916 line_start[perline]= letter;
936 if(200 != httpcode) {
937 failf(data,
"Received HTTP code %d from proxy after CONNECT", httpcode);
949 infof (data,
"Proxy replied OK to CONNECT request\n");
1036 failf(data,
"Empty reply from server");
1046 curlassert((stage == 401) || (stage == 407));
1064 char *ppath = conn->
ppath;
1065 char *host = conn->
name;
1066 const char *te =
"";
1074 http = (
struct HTTP *)malloc(
sizeof(
struct HTTP));
1077 memset(http, 0,
sizeof(
struct HTTP));
1108 result = http_auth_headers(conn, request, ppath, &authdone);
1119 if(data->
set.
cookie && !checkheaders(data,
"Cookie:"))
1126 ptr = checkheaders(data,
"Transfer-Encoding:");
1140 if(!checkheaders(data,
"Transfer-Encoding:")) {
1141 te =
"Transfer-Encoding: chunked\r\n";
1150 ptr = checkheaders(data,
"Host:");
1156 char *
start = ptr+strlen(
"Host:");
1157 while(*start && isspace((
int)*start ))
1162 while(*ptr && !isspace((
int)*ptr) && !(
':'==*ptr))
1222 failf(data,
"failed creating formpost data");
1228 if(!checkheaders(data,
"Pragma:"))
1229 http->
p_pragma =
"Pragma: no-cache\r\n";
1231 if(!checkheaders(data,
"Accept:"))
1232 http->
p_accept =
"Accept: */*\r\n";
1262 size_t readthisamountnow = (size_t)(conn->
resume_from - passed);
1263 size_t actuallyread;
1265 if(readthisamountnow >
BUFSIZE)
1272 passed += actuallyread;
1273 if(actuallyread != readthisamountnow) {
1275 " bytes from the input",
1286 failf(data,
"File already completely uploaded");
1300 !checkheaders(data,
"Range:")) {
1307 !checkheaders(data,
"Content-Range:")) {
1316 conn->
range, total_expected_size-1,
1317 total_expected_size);
1323 aprintf(
"Content-Range: bytes %s/%" FORMAT_OFF_T "\r\n",
1331 const char *httpstring=
1339 req_buffer = add_buffer_init();
1346 add_bufferf(req_buffer,
1391 add_bufferf(req_buffer,
"Cookie: ");
1393 add_bufferf(req_buffer,
1394 "%s%s=%s", count?
"; ":
"", co->
name, co->
value);
1400 add_buffer(req_buffer,
"\r\n", 2);
1407 struct tm *thistime;
1416 #ifdef HAVE_GMTIME_R
1419 thistime = (
struct tm *)gmtime_r(&data->
set.
timevalue, &keeptime);
1424 #ifdef HAVE_STRFTIME
1426 strftime(buf,
BUFSIZE-1,
"%a, %d %b %Y %H:%M:%S GMT", thistime);
1429 strcpy(buf,
"no strftime() support");
1434 add_bufferf(req_buffer,
1435 "If-Modified-Since: %s\r\n", buf);
1438 add_bufferf(req_buffer,
1439 "If-Unmodified-Since: %s\r\n", buf);
1442 add_bufferf(req_buffer,
1443 "Last-Modified: %s\r\n", buf);
1449 ptr = strchr(headers->
data,
':');
1454 while(*ptr && isspace((
int)*ptr))
1460 add_bufferf(req_buffer,
"%s\r\n", headers->
data);
1463 headers = headers->
next;
1477 failf(data,
"Internal HTTP POST error!");
1485 http->
sending = HTTPSEND_BODY;
1489 add_bufferf(req_buffer,
1492 if(!checkheaders(data,
"Expect:")) {
1496 add_bufferf(req_buffer,
1497 "Expect: 100-continue\r\n");
1501 if(!checkheaders(data,
"Content-Type:")) {
1510 char contentType[256];
1511 size_t linelength=0;
1513 sizeof(contentType),
1515 (FILE *)&http->
form);
1517 failf(data,
"Could not get Content-Type header line!");
1520 add_buffer(req_buffer, contentType, linelength);
1524 add_buffer(req_buffer,
"\r\n", 2);
1530 result = add_buffer_send(req_buffer, conn,
1533 failf(data,
"Failed sending POST request");
1550 add_bufferf(req_buffer,
1554 if(!checkheaders(data,
"Expect:")) {
1558 add_bufferf(req_buffer,
1559 "Expect: 100-continue\r\n");
1563 add_buffer(req_buffer,
"\r\n", 2);
1569 result = add_buffer_send(req_buffer, conn,
1572 failf(data,
"Failed sending POST request");
1596 if(!checkheaders(data,
"Content-Length:"))
1599 add_bufferf(req_buffer,
"Content-Length: %" FORMAT_OFF_T"\r\n",
1603 if(!checkheaders(data,
"Content-Type:"))
1604 add_bufferf(req_buffer,
1605 "Content-Type: application/x-www-form-urlencoded\r\n");
1609 if(authdone && (postsize < (100*1024))) {
1618 add_buffer(req_buffer,
"\r\n", 2);
1623 add_buffer(req_buffer, data->
set.
postfields, (
size_t)postsize);
1626 add_bufferf(req_buffer,
"%x\r\n", (
int)postsize);
1627 add_buffer(req_buffer, data->
set.
postfields, (
size_t)postsize);
1628 add_buffer(req_buffer,
"\r\n0\r\n\r\n", 7);
1637 http->
sending = HTTPSEND_BODY;
1645 if(!authdone && !checkheaders(data,
"Expect:")) {
1649 add_bufferf(req_buffer,
1650 "Expect: 100-continue\r\n");
1654 add_buffer(req_buffer,
"\r\n", 2);
1658 add_buffer(req_buffer,
"\r\n", 2);
1668 result = add_buffer_send(req_buffer, conn,
1672 failf(data,
"Failed sending HTTP POST request");
1682 add_buffer(req_buffer,
"\r\n", 2);
1685 result = add_buffer_send(req_buffer, conn,
1689 failf(data,
"Failed sending HTTP request");
struct CookieInfo * cookies
CURLntlm Curl_input_ntlm(struct connectdata *conn, bool proxy, char *header)
union connectdata::@11 proto
bool http_disable_hostname_check_before_authentication
struct DynamicStatic change
CURLcode Curl_http_done(struct connectdata *conn)
#define strnequal(a, b, c)
CURLcode Curl_client_write(struct SessionHandle *data, int type, char *ptr, size_t len)
#define CURL_MAX_WRITE_SIZE
size_t Curl_base64_encode(const char *inp, size_t insize, char **outptr)
#define CURLAUTH_GSSNEGOTIATE
unsigned short remote_port
int Curl_read(struct connectdata *conn, curl_socket_t sockfd, char *buf, size_t buffersize, ssize_t *n)
void Curl_http_auth_stage(struct SessionHandle *data, int stage)
CURLcode Curl_write(struct connectdata *conn, curl_socket_t sockfd, void *mem, size_t len, ssize_t *written)
bool tunnel_thru_httpproxy
GLuint GLuint GLsizei count
CURLcode Curl_http_auth(struct connectdata *conn, int httpcode, char *header)
char uploadbuffer[BUFSIZE+1]
struct curl_slist * headers
void Curl_pgrsSetUploadSize(struct SessionHandle *data, curl_off_t size)
GLsizei GLsizei GLenum GLenum const GLvoid * data
CURLcode Curl_http_connect(struct connectdata *conn)
CURLcode Curl_http(struct connectdata *conn)
CURLdigest Curl_input_digest(struct connectdata *conn, char *header)
#define CLIENTWRITE_HEADER
struct tm * gmtime(const time_t *)
CURLcode Curl_Transfer(struct connectdata *c_conn, int sockindex, curl_off_t size, bool getheader, curl_off_t *bytecountp, int writesockindex, curl_off_t *writecountp)
void Curl_http_auth_act(struct connectdata *conn)
long Curl_tvdiff(struct timeval newer, struct timeval older)
struct SessionHandle * data
#define checkprefix(a, b)
CURLcode Curl_output_digest(struct connectdata *conn, unsigned char *request, unsigned char *uripath)
int Curl_debug(struct SessionHandle *data, curl_infotype type, char *ptr, size_t size)
CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy, bool *ready)
void Curl_safefree(void *ptr)
struct timeval Curl_tvnow(void)
curl_off_t writebytecount
CURLSHcode Curl_share_lock(struct SessionHandle *data, curl_lock_data type, curl_lock_access accesstype)
bool Curl_compareheader(char *headerline, const char *header, const char *content)
struct Cookie * Curl_cookie_getlist(struct CookieInfo *c, char *host, char *path, bool secure)
void Curl_cookie_freelist(struct Cookie *co)
CURLcode Curl_sendf(curl_socket_t sockfd, struct connectdata *conn, const char *fmt,...)
CURLcode Curl_SSLConnect(struct connectdata *conn, int sockindex)
struct connectdata::dynamically_allocated_data allocptr
size_t(* curl_read_callback)(char *buffer, size_t size, size_t nitems, void *instream)
int() curl_strequal(const char *s1, const char *s2)
struct curl_httppost * httppost
curl_TimeCond timecondition
CURLcode Curl_ConnectHTTPProxyTunnel(struct connectdata *conn, int sockindex, char *hostname, int remote_port)
CURLSHcode Curl_share_unlock(struct SessionHandle *data, curl_lock_data type)
int sprintf(idStr &string, const char *fmt,...)