Newer
Older
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
***************************************************************************/
#ifndef CURL_DISABLE_HTTP
#ifdef HAVE_NETDB_H
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include "curl_transfer.h"
#include "curl_sendf.h"
#include "curl_formdata.h"
#include "curl_progress.h"
#include "curl_base64.h"
#include "curl_cookie.h"
#include "curl_strequal.h"
#include "curl_sslgen.h"
#include "curl_http_digest.h"
#include "curl_ntlm_wb.h"
#include "curl_http_negotiate.h"
#include "curl_url.h"
#include "curl_share.h"
#include "curl_hostip.h"
#include "curl_http.h"
#include "curl_select.h"
#include "curl_parsedate.h" /* for the week day and month names */
#include "curl_strtoofft.h"
#include "curl_multiif.h"
#include "curl_rawstr.h"
#include "curl_content_encoding.h"
#include "curl_http_proxy.h"
#include "curl_warnless.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
/* The last #include file should be: */
Patrick Monnerat
committed
/*
* Forward declarations.
*/
Daniel Stenberg
committed
static int http_getsock_do(struct connectdata *conn,
curl_socket_t *socks,
int numsocks);
static int http_should_fail(struct connectdata *conn);
static CURLcode https_connecting(struct connectdata *conn, bool *done);
static int https_getsock(struct connectdata *conn,
curl_socket_t *socks,
int numsocks);
#else
#define https_connecting(x,y) CURLE_COULDNT_CONNECT
Patrick Monnerat
committed
/*
* HTTP handler interface.
*/
const struct Curl_handler Curl_handler_http = {
"HTTP", /* scheme */
ZERO_NULL, /* setup_connection */
Patrick Monnerat
committed
Curl_http, /* do_it */
Curl_http_done, /* done */
ZERO_NULL, /* do_more */
Patrick Monnerat
committed
Curl_http_connect, /* connect_it */
ZERO_NULL, /* connecting */
ZERO_NULL, /* doing */
ZERO_NULL, /* proto_getsock */
Daniel Stenberg
committed
http_getsock_do, /* doing_getsock */
ZERO_NULL, /* domore_getsock */
Daniel Stenberg
committed
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
Patrick Monnerat
committed
PORT_HTTP, /* defport */
Patrick Monnerat
committed
};
#ifdef USE_SSL
/*
* HTTPS handler interface.
*/
const struct Curl_handler Curl_handler_https = {
"HTTPS", /* scheme */
ZERO_NULL, /* setup_connection */
Patrick Monnerat
committed
Curl_http, /* do_it */
Curl_http_done, /* done */
ZERO_NULL, /* do_more */
Patrick Monnerat
committed
Curl_http_connect, /* connect_it */
https_connecting, /* connecting */
ZERO_NULL, /* doing */
https_getsock, /* proto_getsock */
Daniel Stenberg
committed
http_getsock_do, /* doing_getsock */
ZERO_NULL, /* domore_getsock */
Daniel Stenberg
committed
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
Patrick Monnerat
committed
PORT_HTTPS, /* defport */
CURLPROTO_HTTP | CURLPROTO_HTTPS, /* protocol */
Patrick Monnerat
committed
};
#endif
/*
* checkheaders() checks the linked list of custom HTTP headers for a
* particular header (prefix).
*
* Returns a pointer to the first matching header or NULL if none matched.
*/
Daniel Stenberg
committed
char *Curl_checkheaders(struct SessionHandle *data, const char *thisheader)
{
struct curl_slist *head;
size_t thislen = strlen(thisheader);
for(head = data->set.headers; head; head=head->next) {
if(Curl_raw_nequal(head->data, thisheader, thislen))
return head->data;
}
return NULL;
}
/*
* Strip off leading and trailing whitespace from the value in the
* given HTTP header line and return a strdupped copy. Returns NULL in
* case of allocation failure. Returns an empty string if the header value
* consists entirely of whitespace.
*/
static char *copy_header_value(const char *h)
{
const char *start;
const char *end;
char *value;
size_t len;
DEBUGASSERT(h);
/* Find the end of the header name */
while(*h && (*h != ':'))
/* Skip over colon */
++h;
/* Find the first non-space letter */
start = h;
while(*start && ISSPACE(*start))
start++;
/* data is in the host encoding so
use '\r' and '\n' instead of 0x0d and 0x0a */
end = strchr(start, '\r');
if(!end)
end = strchr(start, '\n');
Loading
Loading full blame…