2 * Copyright (c) 2000-2014 Dag-Erling Smørgrav
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
33 * The following copyright applies to the base64 code:
36 * Copyright 1997 Massachusetts Institute of Technology
38 * Permission to use, copy, modify, and distribute this software and
39 * its documentation for any purpose and without fee is hereby
40 * granted, provided that both the above copyright notice and this
41 * permission notice appear in all copies, that both the above
42 * copyright notice and this permission notice appear in all
43 * supporting documentation, and that the name of M.I.T. not be used
44 * in advertising or publicity pertaining to distribution of the
45 * software without specific, written prior permission. M.I.T. makes
46 * no representations about the suitability of this software for any
47 * purpose. It is provided "as is" without express or implied
50 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
51 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
52 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
54 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
57 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
58 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
59 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
60 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 #include <sys/param.h>
65 #include <sys/socket.h>
81 #include <openssl/md5.h>
82 #define MD5Init(c) MD5_Init(c)
83 #define MD5Update(c, data, len) MD5_Update(c, data, len)
84 #define MD5Final(md, c) MD5_Final(md, c)
89 #include <netinet/in.h>
90 #include <netinet/tcp.h>
96 /* Maximum number of redirects to follow */
97 #define MAX_REDIRECT 20
99 /* Symbolic names for reply codes we care about */
101 #define HTTP_PARTIAL 206
102 #define HTTP_MOVED_PERM 301
103 #define HTTP_MOVED_TEMP 302
104 #define HTTP_SEE_OTHER 303
105 #define HTTP_NOT_MODIFIED 304
106 #define HTTP_USE_PROXY 305
107 #define HTTP_TEMP_REDIRECT 307
108 #define HTTP_PERM_REDIRECT 308
109 #define HTTP_NEED_AUTH 401
110 #define HTTP_NEED_PROXY_AUTH 407
111 #define HTTP_BAD_RANGE 416
112 #define HTTP_PROTOCOL_ERROR 999
114 #define HTTP_REDIRECT(xyz) ((xyz) == HTTP_MOVED_PERM \
115 || (xyz) == HTTP_MOVED_TEMP \
116 || (xyz) == HTTP_TEMP_REDIRECT \
117 || (xyz) == HTTP_USE_PROXY \
118 || (xyz) == HTTP_SEE_OTHER)
120 #define HTTP_ERROR(xyz) ((xyz) > 400 && (xyz) < 599)
123 /*****************************************************************************
124 * I/O functions for decoding chunked streams
129 conn_t *conn; /* connection */
130 int chunked; /* chunked mode */
131 char *buf; /* chunk buffer */
132 size_t bufsize; /* size of chunk buffer */
133 ssize_t buflen; /* amount of data currently in buffer */
134 int bufpos; /* current read offset in buffer */
135 int eof; /* end-of-file flag */
136 int error; /* error flag */
137 size_t chunksize; /* remaining size of current chunk */
144 * Get next chunk header
147 http_new_chunk(struct httpio *io)
151 if (fetch_getln(io->conn) == -1)
154 if (io->conn->buflen < 2 || !isxdigit((unsigned char)*io->conn->buf))
157 for (p = io->conn->buf; *p && !isspace((unsigned char)*p); ++p) {
160 if (!isxdigit((unsigned char)*p))
162 if (isdigit((unsigned char)*p)) {
163 io->chunksize = io->chunksize * 16 +
166 io->chunksize = io->chunksize * 16 +
167 10 + tolower((unsigned char)*p) - 'a';
173 io->total += io->chunksize;
174 if (io->chunksize == 0)
175 fprintf(stderr, "%s(): end of last chunk\n", __func__);
177 fprintf(stderr, "%s(): new chunk: %lu (%lu)\n",
178 __func__, (unsigned long)io->chunksize,
179 (unsigned long)io->total);
183 return (io->chunksize);
187 * Grow the input buffer to at least len bytes
190 http_growbuf(struct httpio *io, size_t len)
194 if (io->bufsize >= len)
197 if ((tmp = realloc(io->buf, len)) == NULL)
205 * Fill the input buffer, do chunk decoding on the fly
208 http_fillbuf(struct httpio *io, size_t len)
218 if (io->chunked == 0) {
219 if (http_growbuf(io, len) == -1)
221 if ((nbytes = fetch_read(io->conn, io->buf, len)) == -1) {
230 if (io->chunksize == 0) {
231 switch (http_new_chunk(io)) {
241 if (len > io->chunksize)
243 if (http_growbuf(io, len) == -1)
245 if ((nbytes = fetch_read(io->conn, io->buf, len)) == -1) {
250 io->chunksize -= io->buflen;
252 if (io->chunksize == 0) {
253 if (fetch_read(io->conn, &ch, 1) != 1 || ch != '\r' ||
254 fetch_read(io->conn, &ch, 1) != 1 || ch != '\n')
267 http_readfn(void *v, char *buf, int len)
269 struct httpio *io = (struct httpio *)v;
278 if (!io->buf || io->bufpos == io->buflen) {
279 if ((rlen = http_fillbuf(io, len)) < 0) {
280 if ((errno = io->error) == EINTR)
283 } else if (rlen == 0) {
288 rlen = io->buflen - io->bufpos;
291 memcpy(buf, io->buf + io->bufpos, rlen);
300 http_writefn(void *v, const char *buf, int len)
302 struct httpio *io = (struct httpio *)v;
304 return (fetch_write(io->conn, buf, len));
311 http_closefn(void *v)
313 struct httpio *io = (struct httpio *)v;
316 r = fetch_close(io->conn);
324 * Wrap a file descriptor up
327 http_funopen(conn_t *conn, int chunked)
332 if ((io = calloc(1, sizeof(*io))) == NULL) {
337 io->chunked = chunked;
338 f = funopen(io, http_readfn, http_writefn, NULL, http_closefn);
348 /*****************************************************************************
349 * Helper functions for talking to the server and parsing its replies
362 hdr_transfer_encoding,
363 hdr_www_authenticate,
364 hdr_proxy_authenticate,
367 /* Names of interesting headers */
372 { hdr_content_length, "Content-Length" },
373 { hdr_content_range, "Content-Range" },
374 { hdr_last_modified, "Last-Modified" },
375 { hdr_location, "Location" },
376 { hdr_transfer_encoding, "Transfer-Encoding" },
377 { hdr_www_authenticate, "WWW-Authenticate" },
378 { hdr_proxy_authenticate, "Proxy-Authenticate" },
379 { hdr_unknown, NULL },
383 * Send a formatted line; optionally echo to terminal
386 http_cmd(conn_t *conn, const char *fmt, ...)
394 len = vasprintf(&msg, fmt, ap);
403 r = fetch_putln(conn, msg, len);
415 * Get and parse status line
418 http_get_reply(conn_t *conn)
422 if (fetch_getln(conn) == -1)
425 * A valid status line looks like "HTTP/m.n xyz reason" where m
426 * and n are the major and minor protocol version numbers and xyz
428 * Unfortunately, there are servers out there (NCSA 1.5.1, to name
429 * just one) that do not send a version number, so we can't rely
430 * on finding one, but if we do, insist on it being 1.0 or 1.1.
431 * We don't care about the reason phrase.
433 if (strncmp(conn->buf, "HTTP", 4) != 0)
434 return (HTTP_PROTOCOL_ERROR);
437 if (p[1] != '1' || p[2] != '.' || (p[3] != '0' && p[3] != '1'))
438 return (HTTP_PROTOCOL_ERROR);
442 !isdigit((unsigned char)p[1]) ||
443 !isdigit((unsigned char)p[2]) ||
444 !isdigit((unsigned char)p[3]))
445 return (HTTP_PROTOCOL_ERROR);
447 conn->err = (p[1] - '0') * 100 + (p[2] - '0') * 10 + (p[3] - '0');
452 * Check a header; if the type matches the given string, return a pointer
453 * to the beginning of the value.
456 http_match(const char *str, const char *hdr)
458 while (*str && *hdr &&
459 tolower((unsigned char)*str++) == tolower((unsigned char)*hdr++))
461 if (*str || *hdr != ':')
463 while (*hdr && isspace((unsigned char)*++hdr))
470 * Get the next header and return the appropriate symbolic code. We
471 * need to read one line ahead for checking for a continuation line
472 * belonging to the current header (continuation lines start with
475 * We get called with a fresh line already in the conn buffer, either
476 * from the previous http_next_header() invocation, or, the first
477 * time, from a fetch_getln() performed by our caller.
479 * This stops when we encounter an empty line (we dont read beyond the header
482 * Note that the "headerbuf" is just a place to return the result. Its
483 * contents are not used for the next call. This means that no cleanup
484 * is needed when ie doing another connection, just call the cleanup when
485 * fully done to deallocate memory.
488 /* Limit the max number of continuation lines to some reasonable value */
489 #define HTTP_MAX_CONT_LINES 10
491 /* Place into which to build a header from one or several lines */
493 char *buf; /* buffer */
494 size_t bufsize; /* buffer size */
495 size_t buflen; /* length of buffer contents */
499 init_http_headerbuf(http_headerbuf_t *buf)
507 clean_http_headerbuf(http_headerbuf_t *buf)
511 init_http_headerbuf(buf);
514 /* Remove whitespace at the end of the buffer */
516 http_conn_trimright(conn_t *conn)
518 while (conn->buflen &&
519 isspace((unsigned char)conn->buf[conn->buflen - 1]))
521 conn->buf[conn->buflen] = '\0';
525 http_next_header(conn_t *conn, http_headerbuf_t *hbuf, const char **p)
530 * Have to do the stripping here because of the first line. So
531 * it's done twice for the subsequent lines. No big deal
533 http_conn_trimright(conn);
534 if (conn->buflen == 0)
537 /* Copy the line to the headerbuf */
538 if (hbuf->bufsize < conn->buflen + 1) {
539 if ((hbuf->buf = realloc(hbuf->buf, conn->buflen + 1)) == NULL)
540 return (hdr_syserror);
541 hbuf->bufsize = conn->buflen + 1;
543 strcpy(hbuf->buf, conn->buf);
544 hbuf->buflen = conn->buflen;
547 * Fetch possible continuation lines. Stop at 1st non-continuation
548 * and leave it in the conn buffer
550 for (i = 0; i < HTTP_MAX_CONT_LINES; i++) {
551 if (fetch_getln(conn) == -1)
552 return (hdr_syserror);
555 * Note: we carry on the idea from the previous version
556 * that a pure whitespace line is equivalent to an empty
557 * one (so it's not continuation and will be handled when
558 * we are called next)
560 http_conn_trimright(conn);
561 if (conn->buf[0] != ' ' && conn->buf[0] != "\t"[0])
564 /* Got a continuation line. Concatenate to previous */
565 len = hbuf->buflen + conn->buflen;
566 if (hbuf->bufsize < len + 1) {
568 if ((hbuf->buf = realloc(hbuf->buf, len + 1)) == NULL)
569 return (hdr_syserror);
570 hbuf->bufsize = len + 1;
572 strcpy(hbuf->buf + hbuf->buflen, conn->buf);
573 hbuf->buflen += conn->buflen;
577 * We could check for malformed headers but we don't really care.
578 * A valid header starts with a token immediately followed by a
579 * colon; a token is any sequence of non-control, non-whitespace
580 * characters except "()<>@,;:\\\"{}".
582 for (i = 0; hdr_names[i].num != hdr_unknown; i++)
583 if ((*p = http_match(hdr_names[i].name, hbuf->buf)) != NULL)
584 return (hdr_names[i].num);
586 return (hdr_unknown);
589 /**************************
590 * [Proxy-]Authenticate header parsing
594 * Read doublequote-delimited string into output buffer obuf (allocated
595 * by caller, whose responsibility it is to ensure that it's big enough)
596 * cp points to the first char after the initial '"'
598 * Returns pointer to the first char after the terminating double quote, or
602 http_parse_headerstring(const char *cp, char *obuf)
606 case 0: /* Unterminated string */
609 case '"': /* Ending quote */
624 /* Http auth challenge schemes */
625 typedef enum {HTTPAS_UNKNOWN, HTTPAS_BASIC,HTTPAS_DIGEST} http_auth_schemes_t;
627 /* Data holder for a Basic or Digest challenge. */
629 http_auth_schemes_t scheme;
636 int nc; /* Nonce count */
637 } http_auth_challenge_t;
640 init_http_auth_challenge(http_auth_challenge_t *b)
642 b->scheme = HTTPAS_UNKNOWN;
643 b->realm = b->qop = b->nonce = b->opaque = b->algo = NULL;
644 b->stale = b->nc = 0;
648 clean_http_auth_challenge(http_auth_challenge_t *b)
660 init_http_auth_challenge(b);
663 /* Data holder for an array of challenges offered in an http response. */
664 #define MAX_CHALLENGES 10
666 http_auth_challenge_t *challenges[MAX_CHALLENGES];
667 int count; /* Number of parsed challenges in the array */
668 int valid; /* We did parse an authenticate header */
669 } http_auth_challenges_t;
672 init_http_auth_challenges(http_auth_challenges_t *cs)
675 for (i = 0; i < MAX_CHALLENGES; i++)
676 cs->challenges[i] = NULL;
677 cs->count = cs->valid = 0;
681 clean_http_auth_challenges(http_auth_challenges_t *cs)
684 /* We rely on non-zero pointers being allocated, not on the count */
685 for (i = 0; i < MAX_CHALLENGES; i++) {
686 if (cs->challenges[i] != NULL) {
687 clean_http_auth_challenge(cs->challenges[i]);
688 free(cs->challenges[i]);
691 init_http_auth_challenges(cs);
695 * Enumeration for lexical elements. Separators will be returned as their own
698 typedef enum {HTTPHL_WORD=256, HTTPHL_STRING=257, HTTPHL_END=258,
699 HTTPHL_ERROR = 259} http_header_lex_t;
702 * Determine what kind of token comes next and return possible value
703 * in buf, which is supposed to have been allocated big enough by
704 * caller. Advance input pointer and return element type.
707 http_header_lex(const char **cpp, char *buf)
710 /* Eat initial whitespace */
711 *cpp += strspn(*cpp, " \t");
716 if (**cpp == ',' || **cpp == '=')
717 return (*((*cpp)++));
721 *cpp = http_parse_headerstring(++*cpp, buf);
723 return (HTTPHL_ERROR);
724 return (HTTPHL_STRING);
727 /* Read other token, until separator or whitespace */
728 l = strcspn(*cpp, " \t,=");
729 memcpy(buf, *cpp, l);
732 return (HTTPHL_WORD);
736 * Read challenges from http xxx-authenticate header and accumulate them
737 * in the challenges list structure.
739 * Headers with multiple challenges are specified by rfc2617, but
740 * servers (ie: squid) often send them in separate headers instead,
741 * which in turn is forbidden by the http spec (multiple headers with
742 * the same name are only allowed for pure comma-separated lists, see
745 * We support both approaches anyway
748 http_parse_authenticate(const char *cp, http_auth_challenges_t *cs)
751 http_header_lex_t lex;
752 char *key = malloc(strlen(cp) + 1);
753 char *value = malloc(strlen(cp) + 1);
754 char *buf = malloc(strlen(cp) + 1);
756 if (key == NULL || value == NULL || buf == NULL) {
761 /* In any case we've seen the header and we set the valid bit */
764 /* Need word first */
765 lex = http_header_lex(&cp, key);
766 if (lex != HTTPHL_WORD)
769 /* Loop on challenges */
770 for (; cs->count < MAX_CHALLENGES; cs->count++) {
771 cs->challenges[cs->count] =
772 malloc(sizeof(http_auth_challenge_t));
773 if (cs->challenges[cs->count] == NULL) {
777 init_http_auth_challenge(cs->challenges[cs->count]);
778 if (!strcasecmp(key, "basic")) {
779 cs->challenges[cs->count]->scheme = HTTPAS_BASIC;
780 } else if (!strcasecmp(key, "digest")) {
781 cs->challenges[cs->count]->scheme = HTTPAS_DIGEST;
783 cs->challenges[cs->count]->scheme = HTTPAS_UNKNOWN;
785 * Continue parsing as basic or digest may
786 * follow, and the syntax is the same for
787 * all. We'll just ignore this one when
788 * looking at the list
792 /* Loop on attributes */
795 lex = http_header_lex(&cp, key);
796 if (lex != HTTPHL_WORD)
800 lex = http_header_lex(&cp, buf);
805 lex = http_header_lex(&cp, value);
806 if (lex != HTTPHL_WORD && lex != HTTPHL_STRING)
809 if (!strcasecmp(key, "realm"))
810 cs->challenges[cs->count]->realm =
812 else if (!strcasecmp(key, "qop"))
813 cs->challenges[cs->count]->qop =
815 else if (!strcasecmp(key, "nonce"))
816 cs->challenges[cs->count]->nonce =
818 else if (!strcasecmp(key, "opaque"))
819 cs->challenges[cs->count]->opaque =
821 else if (!strcasecmp(key, "algorithm"))
822 cs->challenges[cs->count]->algo =
824 else if (!strcasecmp(key, "stale"))
825 cs->challenges[cs->count]->stale =
826 strcasecmp(value, "no");
827 /* Else ignore unknown attributes */
829 /* Comma or Next challenge or End */
830 lex = http_header_lex(&cp, key);
832 * If we get a word here, this is the beginning of the
833 * next challenge. Break the attributes loop
835 if (lex == HTTPHL_WORD)
838 if (lex == HTTPHL_END) {
839 /* End while looking for ',' is normal exit */
844 /* Anything else is an error */
848 } /* End attributes loop */
849 } /* End challenge loop */
852 * Challenges max count exceeded. This really can't happen
853 * with normal data, something's fishy -> error
868 * Parse a last-modified header
871 http_parse_mtime(const char *p, time_t *mtime)
876 strncpy(locale, setlocale(LC_TIME, NULL), sizeof(locale));
877 setlocale(LC_TIME, "C");
878 r = strptime(p, "%a, %d %b %Y %H:%M:%S GMT", &tm);
880 * Some proxies use UTC in response, but it should still be
881 * parsed. RFC2616 states GMT and UTC are exactly equal for HTTP.
884 r = strptime(p, "%a, %d %b %Y %H:%M:%S UTC", &tm);
885 /* XXX should add support for date-2 and date-3 */
886 setlocale(LC_TIME, locale);
889 DEBUG(fprintf(stderr, "last modified: [%04d-%02d-%02d "
891 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
892 tm.tm_hour, tm.tm_min, tm.tm_sec));
893 *mtime = timegm(&tm);
898 * Parse a content-length header
901 http_parse_length(const char *p, off_t *length)
905 for (len = 0; *p && isdigit((unsigned char)*p); ++p)
906 len = len * 10 + (*p - '0');
909 DEBUG(fprintf(stderr, "content length: [%lld]\n",
916 * Parse a content-range header
919 http_parse_range(const char *p, off_t *offset, off_t *length, off_t *size)
921 off_t first, last, len;
923 if (strncasecmp(p, "bytes ", 6) != 0)
930 for (first = 0; *p && isdigit((unsigned char)*p); ++p)
931 first = first * 10 + *p - '0';
934 for (last = 0, ++p; *p && isdigit((unsigned char)*p); ++p)
935 last = last * 10 + *p - '0';
937 if (first > last || *p != '/')
939 for (len = 0, ++p; *p && isdigit((unsigned char)*p); ++p)
940 len = len * 10 + *p - '0';
941 if (*p || len < last - first + 1)
944 DEBUG(fprintf(stderr, "content range: [*/%lld]\n",
948 DEBUG(fprintf(stderr, "content range: [%lld-%lld/%lld]\n",
949 (long long)first, (long long)last, (long long)len));
950 *length = last - first + 1;
958 /*****************************************************************************
959 * Helper functions for authorization
966 http_base64(const char *src)
968 static const char base64[] =
969 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
970 "abcdefghijklmnopqrstuvwxyz"
977 if ((str = malloc(((l + 2) / 3) * 4 + 1)) == NULL)
983 t = (src[0] << 16) | (src[1] << 8) | src[2];
984 dst[0] = base64[(t >> 18) & 0x3f];
985 dst[1] = base64[(t >> 12) & 0x3f];
986 dst[2] = base64[(t >> 6) & 0x3f];
987 dst[3] = base64[(t >> 0) & 0x3f];
994 t = (src[0] << 16) | (src[1] << 8);
995 dst[0] = base64[(t >> 18) & 0x3f];
996 dst[1] = base64[(t >> 12) & 0x3f];
997 dst[2] = base64[(t >> 6) & 0x3f];
1004 dst[0] = base64[(t >> 18) & 0x3f];
1005 dst[1] = base64[(t >> 12) & 0x3f];
1006 dst[2] = dst[3] = '=';
1020 * Extract authorization parameters from environment value.
1021 * The value is like scheme:realm:user:pass
1028 } http_auth_params_t;
1031 init_http_auth_params(http_auth_params_t *s)
1033 s->scheme = s->realm = s->user = s->password = NULL;
1037 clean_http_auth_params(http_auth_params_t *s)
1047 init_http_auth_params(s);
1051 http_authfromenv(const char *p, http_auth_params_t *parms)
1055 char *str = strdup(p);
1063 if ((ve = strchr(v, ':')) == NULL)
1067 if ((parms->scheme = strdup(v)) == NULL) {
1073 if ((ve = strchr(v, ':')) == NULL)
1077 if ((parms->realm = strdup(v)) == NULL) {
1083 if ((ve = strchr(v, ':')) == NULL)
1087 if ((parms->user = strdup(v)) == NULL) {
1094 if ((parms->password = strdup(v)) == NULL) {
1101 clean_http_auth_params(parms);
1109 * Digest response: the code to compute the digest is taken from the
1110 * sample implementation in RFC2616
1116 typedef char HASH[HASHLEN];
1117 #define HASHHEXLEN 32
1118 typedef char HASHHEX[HASHHEXLEN+1];
1120 static const char *hexchars = "0123456789abcdef";
1122 CvtHex(IN HASH Bin, OUT HASHHEX Hex)
1127 for (i = 0; i < HASHLEN; i++) {
1128 j = (Bin[i] >> 4) & 0xf;
1129 Hex[i*2] = hexchars[j];
1131 Hex[i*2+1] = hexchars[j];
1133 Hex[HASHHEXLEN] = '\0';
1136 /* calculate H(A1) as per spec */
1140 IN char * pszUserName,
1142 IN char * pszPassword,
1144 IN char * pszCNonce,
1145 OUT HASHHEX SessionKey
1152 MD5Update(&Md5Ctx, pszUserName, strlen(pszUserName));
1153 MD5Update(&Md5Ctx, ":", 1);
1154 MD5Update(&Md5Ctx, pszRealm, strlen(pszRealm));
1155 MD5Update(&Md5Ctx, ":", 1);
1156 MD5Update(&Md5Ctx, pszPassword, strlen(pszPassword));
1157 MD5Final(HA1, &Md5Ctx);
1158 if (strcasecmp(pszAlg, "md5-sess") == 0) {
1161 MD5Update(&Md5Ctx, HA1, HASHLEN);
1162 MD5Update(&Md5Ctx, ":", 1);
1163 MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
1164 MD5Update(&Md5Ctx, ":", 1);
1165 MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
1166 MD5Final(HA1, &Md5Ctx);
1168 CvtHex(HA1, SessionKey);
1171 /* calculate request-digest/response-digest as per HTTP Digest spec */
1174 IN HASHHEX HA1, /* H(A1) */
1175 IN char * pszNonce, /* nonce from server */
1176 IN char * pszNonceCount, /* 8 hex digits */
1177 IN char * pszCNonce, /* client nonce */
1178 IN char * pszQop, /* qop-value: "", "auth", "auth-int" */
1179 IN char * pszMethod, /* method from the request */
1180 IN char * pszDigestUri, /* requested URL */
1181 IN HASHHEX HEntity, /* H(entity body) if qop="auth-int" */
1182 OUT HASHHEX Response /* request-digest or response-digest */
1185 /* DEBUG(fprintf(stderr,
1186 "Calc: HA1[%s] Nonce[%s] qop[%s] method[%s] URI[%s]\n",
1187 HA1, pszNonce, pszQop, pszMethod, pszDigestUri));*/
1195 MD5Update(&Md5Ctx, pszMethod, strlen(pszMethod));
1196 MD5Update(&Md5Ctx, ":", 1);
1197 MD5Update(&Md5Ctx, pszDigestUri, strlen(pszDigestUri));
1198 if (strcasecmp(pszQop, "auth-int") == 0) {
1199 MD5Update(&Md5Ctx, ":", 1);
1200 MD5Update(&Md5Ctx, HEntity, HASHHEXLEN);
1202 MD5Final(HA2, &Md5Ctx);
1203 CvtHex(HA2, HA2Hex);
1205 // calculate response
1207 MD5Update(&Md5Ctx, HA1, HASHHEXLEN);
1208 MD5Update(&Md5Ctx, ":", 1);
1209 MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
1210 MD5Update(&Md5Ctx, ":", 1);
1212 MD5Update(&Md5Ctx, pszNonceCount, strlen(pszNonceCount));
1213 MD5Update(&Md5Ctx, ":", 1);
1214 MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
1215 MD5Update(&Md5Ctx, ":", 1);
1216 MD5Update(&Md5Ctx, pszQop, strlen(pszQop));
1217 MD5Update(&Md5Ctx, ":", 1);
1219 MD5Update(&Md5Ctx, HA2Hex, HASHHEXLEN);
1220 MD5Final(RespHash, &Md5Ctx);
1221 CvtHex(RespHash, Response);
1225 * Generate/Send a Digest authorization header
1226 * This looks like: [Proxy-]Authorization: credentials
1228 * credentials = "Digest" digest-response
1229 * digest-response = 1#( username | realm | nonce | digest-uri
1230 * | response | [ algorithm ] | [cnonce] |
1231 * [opaque] | [message-qop] |
1232 * [nonce-count] | [auth-param] )
1233 * username = "username" "=" username-value
1234 * username-value = quoted-string
1235 * digest-uri = "uri" "=" digest-uri-value
1236 * digest-uri-value = request-uri ; As specified by HTTP/1.1
1237 * message-qop = "qop" "=" qop-value
1238 * cnonce = "cnonce" "=" cnonce-value
1239 * cnonce-value = nonce-value
1240 * nonce-count = "nc" "=" nc-value
1242 * response = "response" "=" request-digest
1243 * request-digest = <"> 32LHEX <">
1246 http_digest_auth(conn_t *conn, const char *hdr, http_auth_challenge_t *c,
1247 http_auth_params_t *parms, struct url *url)
1250 char noncecount[10];
1252 char *options = NULL;
1254 if (!c->realm || !c->nonce) {
1255 DEBUG(fprintf(stderr, "realm/nonce not set in challenge\n"));
1259 c->algo = strdup("");
1261 if (asprintf(&options, "%s%s%s%s",
1262 *c->algo? ",algorithm=" : "", c->algo,
1263 c->opaque? ",opaque=" : "", c->opaque?c->opaque:"")== -1)
1267 c->qop = strdup("");
1272 sprintf(noncecount, "%08x", c->nc);
1273 /* We don't try very hard with the cnonce ... */
1274 sprintf(cnonce, "%x%lx", getpid(), (unsigned long)time(0));
1278 DigestCalcHA1(c->algo, parms->user, c->realm,
1279 parms->password, c->nonce, cnonce, HA1);
1280 DEBUG(fprintf(stderr, "HA1: [%s]\n", HA1));
1282 DigestCalcResponse(HA1, c->nonce, noncecount, cnonce, c->qop,
1283 "GET", url->doc, "", digest);
1286 r = http_cmd(conn, "%s: Digest username=\"%s\",realm=\"%s\","
1287 "nonce=\"%s\",uri=\"%s\",response=\"%s\","
1288 "qop=\"auth\", cnonce=\"%s\", nc=%s%s",
1289 hdr, parms->user, c->realm,
1290 c->nonce, url->doc, digest,
1291 cnonce, noncecount, options);
1293 r = http_cmd(conn, "%s: Digest username=\"%s\",realm=\"%s\","
1294 "nonce=\"%s\",uri=\"%s\",response=\"%s\"%s",
1295 hdr, parms->user, c->realm,
1296 c->nonce, url->doc, digest, options);
1304 * Encode username and password
1307 http_basic_auth(conn_t *conn, const char *hdr, const char *usr, const char *pwd)
1312 DEBUG(fprintf(stderr, "basic: usr: [%s]\n", usr));
1313 DEBUG(fprintf(stderr, "basic: pwd: [%s]\n", pwd));
1314 if (asprintf(&upw, "%s:%s", usr, pwd) == -1)
1316 auth = http_base64(upw);
1320 r = http_cmd(conn, "%s: Basic %s", hdr, auth);
1326 * Chose the challenge to answer and call the appropriate routine to
1327 * produce the header.
1330 http_authorize(conn_t *conn, const char *hdr, http_auth_challenges_t *cs,
1331 http_auth_params_t *parms, struct url *url)
1333 http_auth_challenge_t *basic = NULL;
1334 http_auth_challenge_t *digest = NULL;
1337 /* If user or pass are null we're not happy */
1338 if (!parms->user || !parms->password) {
1339 DEBUG(fprintf(stderr, "NULL usr or pass\n"));
1343 /* Look for a Digest and a Basic challenge */
1344 for (i = 0; i < cs->count; i++) {
1345 if (cs->challenges[i]->scheme == HTTPAS_BASIC)
1346 basic = cs->challenges[i];
1347 if (cs->challenges[i]->scheme == HTTPAS_DIGEST)
1348 digest = cs->challenges[i];
1351 /* Error if "Digest" was specified and there is no Digest challenge */
1352 if (!digest && (parms->scheme &&
1353 !strcasecmp(parms->scheme, "digest"))) {
1354 DEBUG(fprintf(stderr,
1355 "Digest auth in env, not supported by peer\n"));
1359 * If "basic" was specified in the environment, or there is no Digest
1360 * challenge, do the basic thing. Don't need a challenge for this,
1361 * so no need to check basic!=NULL
1363 if (!digest || (parms->scheme && !strcasecmp(parms->scheme,"basic")))
1364 return (http_basic_auth(conn,hdr,parms->user,parms->password));
1366 /* Else, prefer digest. We just checked that it's not NULL */
1367 return (http_digest_auth(conn, hdr, digest, parms, url));
1370 /*****************************************************************************
1371 * Helper functions for connecting to a server or proxy
1375 * Connect to the correct HTTP server or proxy.
1378 http_connect(struct url *URL, struct url *purl, const char *flags)
1391 verbose = CHECK_FLAG('v');
1392 if (CHECK_FLAG('4'))
1395 else if (CHECK_FLAG('6'))
1399 curl = (purl != NULL) ? purl : URL;
1401 if ((conn = fetch_connect(curl->host, curl->port, af, verbose)) == NULL)
1402 /* fetch_connect() has already set an error code */
1404 if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0 && purl) {
1405 http_cmd(conn, "CONNECT %s:%d HTTP/1.1",
1406 URL->host, URL->port);
1407 http_cmd(conn, "Host: %s:%d",
1408 URL->host, URL->port);
1410 if (http_get_reply(conn) != HTTP_OK) {
1414 http_get_reply(conn);
1416 if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0 &&
1417 fetch_ssl(conn, URL, verbose) == -1) {
1426 setsockopt(conn->sd, IPPROTO_TCP, TCP_NOPUSH, &val, sizeof(val));
1432 http_get_proxy(struct url * url, const char *flags)
1437 if (flags != NULL && strchr(flags, 'd') != NULL)
1439 if (fetch_no_proxy_match(url->host))
1441 if (((p = getenv("HTTP_PROXY")) || (p = getenv("http_proxy"))) &&
1442 *p && (purl = fetchParseURL(p))) {
1444 strcpy(purl->scheme, SCHEME_HTTP);
1446 purl->port = fetch_default_proxy_port(purl->scheme);
1447 if (strcasecmp(purl->scheme, SCHEME_HTTP) == 0)
1455 http_print_html(FILE *out, FILE *in)
1462 while ((line = fgetln(in, &len)) != NULL) {
1463 while (len && isspace((unsigned char)line[len - 1]))
1465 for (p = q = line; q < line + len; ++q) {
1466 if (comment && *q == '-') {
1467 if (q + 2 < line + len &&
1468 strcmp(q, "-->") == 0) {
1472 } else if (tag && !comment && *q == '>') {
1475 } else if (!tag && *q == '<') {
1477 fwrite(p, q - p, 1, out);
1479 if (q + 3 < line + len &&
1480 strcmp(q, "<!--") == 0) {
1487 fwrite(p, q - p, 1, out);
1493 /*****************************************************************************
1498 http_request(struct url *URL, const char *op, struct url_stat *us,
1499 struct url *purl, const char *flags)
1502 return (http_request_body(URL, op, us, purl, flags, NULL, NULL));
1506 * Send a request and process the reply
1508 * XXX This function is way too long, the do..while loop should be split
1509 * XXX off into a separate function.
1512 http_request_body(struct url *URL, const char *op, struct url_stat *us,
1513 struct url *purl, const char *flags, const char *content_type,
1517 char hbuf[MAXHOSTNAMELEN + 7], *host;
1519 struct url *url, *new;
1520 int chunked, direct, ims, noredirect, verbose;
1522 off_t offset, clength, length, size;
1527 struct tm *timestruct;
1528 http_headerbuf_t headerbuf;
1529 http_auth_challenges_t server_challenges;
1530 http_auth_challenges_t proxy_challenges;
1533 /* The following calls don't allocate anything */
1534 init_http_headerbuf(&headerbuf);
1535 init_http_auth_challenges(&server_challenges);
1536 init_http_auth_challenges(&proxy_challenges);
1538 direct = CHECK_FLAG('d');
1539 noredirect = CHECK_FLAG('A');
1540 verbose = CHECK_FLAG('v');
1541 ims = CHECK_FLAG('i');
1543 if (direct && purl) {
1548 /* try the provided URL first */
1554 e = HTTP_PROTOCOL_ERROR;
1566 url->port = fetch_default_port(url->scheme);
1568 /* were we redirected to an FTP URL? */
1569 if (purl == NULL && strcmp(url->scheme, SCHEME_FTP) == 0) {
1570 if (strcmp(op, "GET") == 0)
1571 return (ftp_request(url, "RETR", us, purl, flags));
1572 else if (strcmp(op, "HEAD") == 0)
1573 return (ftp_request(url, "STAT", us, purl, flags));
1576 /* connect to server or proxy */
1577 if ((conn = http_connect(url, purl, flags)) == NULL)
1582 if (strchr(url->host, ':')) {
1583 snprintf(hbuf, sizeof(hbuf), "[%s]", url->host);
1587 if (url->port != fetch_default_port(url->scheme)) {
1592 snprintf(hbuf + strlen(hbuf),
1593 sizeof(hbuf) - strlen(hbuf), ":%d", url->port);
1598 fetch_info("requesting %s://%s%s",
1599 url->scheme, host, url->doc);
1600 if (purl && strcasecmp(URL->scheme, SCHEME_HTTPS) != 0) {
1601 http_cmd(conn, "%s %s://%s%s HTTP/1.1",
1602 op, url->scheme, host, url->doc);
1604 http_cmd(conn, "%s %s HTTP/1.1",
1608 if (ims && url->ims_time) {
1609 timestruct = gmtime((time_t *)&url->ims_time);
1610 (void)strftime(timebuf, 80, "%a, %d %b %Y %T GMT",
1613 fetch_info("If-Modified-Since: %s", timebuf);
1614 http_cmd(conn, "If-Modified-Since: %s", timebuf);
1617 http_cmd(conn, "Host: %s", host);
1620 * Proxy authorization: we only send auth after we received
1621 * a 407 error. We do not first try basic anyway (changed
1622 * when support was added for digest-auth)
1624 if (purl && proxy_challenges.valid) {
1625 http_auth_params_t aparams;
1626 init_http_auth_params(&aparams);
1627 if (*purl->user || *purl->pwd) {
1628 aparams.user = purl->user ?
1629 strdup(purl->user) : strdup("");
1630 aparams.password = purl->pwd?
1631 strdup(purl->pwd) : strdup("");
1632 } else if ((p = getenv("HTTP_PROXY_AUTH")) != NULL &&
1634 if (http_authfromenv(p, &aparams) < 0) {
1635 http_seterr(HTTP_NEED_PROXY_AUTH);
1639 http_authorize(conn, "Proxy-Authorization",
1640 &proxy_challenges, &aparams, url);
1641 clean_http_auth_params(&aparams);
1645 * Server authorization: we never send "a priori"
1646 * Basic auth, which used to be done if user/pass were
1647 * set in the url. This would be weird because we'd send the
1648 * password in the clear even if Digest is finally to be
1649 * used (it would have made more sense for the
1650 * pre-digest version to do this when Basic was specified
1651 * in the environment)
1653 if (server_challenges.valid) {
1654 http_auth_params_t aparams;
1655 init_http_auth_params(&aparams);
1656 if (*url->user || *url->pwd) {
1657 aparams.user = url->user ?
1658 strdup(url->user) : strdup("");
1659 aparams.password = url->pwd ?
1660 strdup(url->pwd) : strdup("");
1661 } else if ((p = getenv("HTTP_AUTH")) != NULL &&
1663 if (http_authfromenv(p, &aparams) < 0) {
1664 http_seterr(HTTP_NEED_AUTH);
1667 } else if (fetchAuthMethod &&
1668 fetchAuthMethod(url) == 0) {
1669 aparams.user = url->user ?
1670 strdup(url->user) : strdup("");
1671 aparams.password = url->pwd ?
1672 strdup(url->pwd) : strdup("");
1674 http_seterr(HTTP_NEED_AUTH);
1677 http_authorize(conn, "Authorization",
1678 &server_challenges, &aparams, url);
1679 clean_http_auth_params(&aparams);
1683 if ((p = getenv("HTTP_ACCEPT")) != NULL) {
1685 http_cmd(conn, "Accept: %s", p);
1687 http_cmd(conn, "Accept: */*");
1689 if ((p = getenv("HTTP_REFERER")) != NULL && *p != '\0') {
1690 if (strcasecmp(p, "auto") == 0)
1691 http_cmd(conn, "Referer: %s://%s%s",
1692 url->scheme, host, url->doc);
1694 http_cmd(conn, "Referer: %s", p);
1696 if ((p = getenv("HTTP_USER_AGENT")) != NULL) {
1697 /* no User-Agent if defined but empty */
1699 http_cmd(conn, "User-Agent: %s", p);
1701 /* default User-Agent */
1702 http_cmd(conn, "User-Agent: %s " _LIBFETCH_VER,
1705 if (url->offset > 0)
1706 http_cmd(conn, "Range: bytes=%lld-", (long long)url->offset);
1707 http_cmd(conn, "Connection: close");
1710 body_len = strlen(body);
1711 http_cmd(conn, "Content-Length: %zu", body_len);
1712 if (content_type != NULL)
1713 http_cmd(conn, "Content-Type: %s", content_type);
1719 fetch_write(conn, body, body_len);
1722 * Force the queued request to be dispatched. Normally, one
1723 * would do this with shutdown(2) but squid proxies can be
1724 * configured to disallow such half-closed connections. To
1725 * be compatible with such configurations, fiddle with socket
1726 * options to force the pending data to be written.
1729 setsockopt(conn->sd, IPPROTO_TCP, TCP_NOPUSH, &val,
1732 setsockopt(conn->sd, IPPROTO_TCP, TCP_NODELAY, &val,
1736 switch (http_get_reply(conn)) {
1739 case HTTP_NOT_MODIFIED:
1742 case HTTP_MOVED_PERM:
1743 case HTTP_MOVED_TEMP:
1744 case HTTP_SEE_OTHER:
1745 case HTTP_USE_PROXY:
1747 * Not so fine, but we still have to read the
1748 * headers to get the new location.
1751 case HTTP_NEED_AUTH:
1752 if (server_challenges.valid) {
1754 * We already sent out authorization code,
1755 * so there's nothing more we can do.
1757 http_seterr(conn->err);
1760 /* try again, but send the password this time */
1762 fetch_info("server requires authorization");
1764 case HTTP_NEED_PROXY_AUTH:
1765 if (proxy_challenges.valid) {
1767 * We already sent our proxy
1768 * authorization code, so there's
1769 * nothing more we can do. */
1770 http_seterr(conn->err);
1773 /* try again, but send the password this time */
1775 fetch_info("proxy requires authorization");
1777 case HTTP_BAD_RANGE:
1779 * This can happen if we ask for 0 bytes because
1780 * we already have the whole file. Consider this
1781 * a success for now, and check sizes later.
1784 case HTTP_PROTOCOL_ERROR:
1790 http_seterr(conn->err);
1793 /* fall through so we can get the full error message */
1796 /* get headers. http_next_header expects one line readahead */
1797 if (fetch_getln(conn) == -1) {
1802 switch ((h = http_next_header(conn, &headerbuf, &p))) {
1807 http_seterr(HTTP_PROTOCOL_ERROR);
1809 case hdr_content_length:
1810 http_parse_length(p, &clength);
1812 case hdr_content_range:
1813 http_parse_range(p, &offset, &length, &size);
1815 case hdr_last_modified:
1816 http_parse_mtime(p, &mtime);
1819 if (!HTTP_REDIRECT(conn->err))
1822 * if the A flag is set, we don't follow
1823 * temporary redirects.
1826 conn->err != HTTP_MOVED_PERM &&
1827 conn->err != HTTP_PERM_REDIRECT &&
1828 conn->err != HTTP_USE_PROXY) {
1835 fetch_info("%d redirect to %s", conn->err, p);
1838 new = fetchMakeURL(url->scheme, url->host, url->port, p,
1839 url->user, url->pwd);
1841 new = fetchParseURL(p);
1843 /* XXX should set an error code */
1844 DEBUG(fprintf(stderr, "failed to parse new URL\n"));
1848 /* Only copy credentials if the host matches */
1849 if (!strcmp(new->host, url->host) && !*new->user && !*new->pwd) {
1850 strcpy(new->user, url->user);
1851 strcpy(new->pwd, url->pwd);
1853 new->offset = url->offset;
1854 new->length = url->length;
1856 case hdr_transfer_encoding:
1858 chunked = (strcasecmp(p, "chunked") == 0);
1860 case hdr_www_authenticate:
1861 if (conn->err != HTTP_NEED_AUTH)
1863 if (http_parse_authenticate(p, &server_challenges) == 0)
1866 case hdr_proxy_authenticate:
1867 if (conn->err != HTTP_NEED_PROXY_AUTH)
1869 if (http_parse_authenticate(p, &proxy_challenges) == 0)
1878 } while (h > hdr_end);
1880 /* we need to provide authentication */
1881 if (conn->err == HTTP_NEED_AUTH ||
1882 conn->err == HTTP_NEED_PROXY_AUTH) {
1884 if ((conn->err == HTTP_NEED_AUTH &&
1885 !server_challenges.valid) ||
1886 (conn->err == HTTP_NEED_PROXY_AUTH &&
1887 !proxy_challenges.valid)) {
1888 /* 401/7 but no www/proxy-authenticate ?? */
1889 DEBUG(fprintf(stderr, "401/7 and no auth header\n"));
1897 /* requested range not satisfiable */
1898 if (conn->err == HTTP_BAD_RANGE) {
1899 if (url->offset == size && url->length == 0) {
1900 /* asked for 0 bytes; fake it */
1901 offset = url->offset;
1903 conn->err = HTTP_OK;
1906 http_seterr(conn->err);
1911 /* we have a hit or an error */
1912 if (conn->err == HTTP_OK
1913 || conn->err == HTTP_NOT_MODIFIED
1914 || conn->err == HTTP_PARTIAL
1915 || HTTP_ERROR(conn->err))
1918 /* all other cases: we got a redirect */
1920 clean_http_auth_challenges(&server_challenges);
1924 DEBUG(fprintf(stderr, "redirect with no new location\n"));
1932 /* we failed, or ran out of retries */
1938 DEBUG(fprintf(stderr, "offset %lld, length %lld,"
1939 " size %lld, clength %lld\n",
1940 (long long)offset, (long long)length,
1941 (long long)size, (long long)clength));
1943 if (conn->err == HTTP_NOT_MODIFIED) {
1944 http_seterr(HTTP_NOT_MODIFIED);
1948 /* check for inconsistencies */
1949 if (clength != -1 && length != -1 && clength != length) {
1950 http_seterr(HTTP_PROTOCOL_ERROR);
1956 length = offset + clength;
1957 if (length != -1 && size != -1 && length != size) {
1958 http_seterr(HTTP_PROTOCOL_ERROR);
1967 us->atime = us->mtime = mtime;
1971 if (URL->offset > 0 && offset > URL->offset) {
1972 http_seterr(HTTP_PROTOCOL_ERROR);
1976 /* report back real offset and size */
1977 URL->offset = offset;
1978 URL->length = clength;
1980 /* wrap it up in a FILE */
1981 if ((f = http_funopen(conn, chunked)) == NULL) {
1991 if (HTTP_ERROR(conn->err)) {
1992 http_print_html(stderr, f);
1996 clean_http_headerbuf(&headerbuf);
1997 clean_http_auth_challenges(&server_challenges);
1998 clean_http_auth_challenges(&proxy_challenges);
2008 clean_http_headerbuf(&headerbuf);
2009 clean_http_auth_challenges(&server_challenges);
2010 clean_http_auth_challenges(&proxy_challenges);
2015 /*****************************************************************************
2020 * Retrieve and stat a file by HTTP
2023 fetchXGetHTTP(struct url *URL, struct url_stat *us, const char *flags)
2025 return (http_request(URL, "GET", us, http_get_proxy(URL, flags), flags));
2029 * Retrieve a file by HTTP
2032 fetchGetHTTP(struct url *URL, const char *flags)
2034 return (fetchXGetHTTP(URL, NULL, flags));
2038 * Store a file by HTTP
2041 fetchPutHTTP(struct url *URL __unused, const char *flags __unused)
2043 warnx("fetchPutHTTP(): not implemented");
2048 * Get an HTTP document's metadata
2051 fetchStatHTTP(struct url *URL, struct url_stat *us, const char *flags)
2055 f = http_request(URL, "HEAD", us, http_get_proxy(URL, flags), flags);
2066 fetchListHTTP(struct url *url __unused, const char *flags __unused)
2068 warnx("fetchListHTTP(): not implemented");
2073 fetchReqHTTP(struct url *URL, const char *method, const char *flags,
2074 const char *content_type, const char *body)
2077 return (http_request_body(URL, method, NULL, http_get_proxy(URL, flags),
2078 flags, content_type, body));