2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2000-2014 Dag-Erling Smørgrav
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer
12 * in this position and unchanged.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
35 * The following copyright applies to the base64 code:
38 * Copyright 1997 Massachusetts Institute of Technology
40 * Permission to use, copy, modify, and distribute this software and
41 * its documentation for any purpose and without fee is hereby
42 * granted, provided that both the above copyright notice and this
43 * permission notice appear in all copies, that both the above
44 * copyright notice and this permission notice appear in all
45 * supporting documentation, and that the name of M.I.T. not be used
46 * in advertising or publicity pertaining to distribution of the
47 * software without specific, written prior permission. M.I.T. makes
48 * no representations about the suitability of this software for any
49 * purpose. It is provided "as is" without express or implied
52 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
53 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
54 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
55 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
56 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
59 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
60 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
61 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
62 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 #include <sys/param.h>
67 #include <sys/socket.h>
83 #include <openssl/md5.h>
84 #define MD5Init(c) MD5_Init(c)
85 #define MD5Update(c, data, len) MD5_Update(c, data, len)
86 #define MD5Final(md, c) MD5_Final(md, c)
91 #include <netinet/in.h>
92 #include <netinet/tcp.h>
98 /* Maximum number of redirects to follow */
99 #define MAX_REDIRECT 20
101 /* Symbolic names for reply codes we care about */
103 #define HTTP_PARTIAL 206
104 #define HTTP_MOVED_PERM 301
105 #define HTTP_MOVED_TEMP 302
106 #define HTTP_SEE_OTHER 303
107 #define HTTP_NOT_MODIFIED 304
108 #define HTTP_USE_PROXY 305
109 #define HTTP_TEMP_REDIRECT 307
110 #define HTTP_PERM_REDIRECT 308
111 #define HTTP_NEED_AUTH 401
112 #define HTTP_NEED_PROXY_AUTH 407
113 #define HTTP_BAD_RANGE 416
114 #define HTTP_PROTOCOL_ERROR 999
116 #define HTTP_REDIRECT(xyz) ((xyz) == HTTP_MOVED_PERM \
117 || (xyz) == HTTP_MOVED_TEMP \
118 || (xyz) == HTTP_TEMP_REDIRECT \
119 || (xyz) == HTTP_PERM_REDIRECT \
120 || (xyz) == HTTP_USE_PROXY \
121 || (xyz) == HTTP_SEE_OTHER)
123 #define HTTP_ERROR(xyz) ((xyz) >= 400 && (xyz) <= 599)
126 /*****************************************************************************
127 * I/O functions for decoding chunked streams
132 conn_t *conn; /* connection */
133 int chunked; /* chunked mode */
134 char *buf; /* chunk buffer */
135 size_t bufsize; /* size of chunk buffer */
136 size_t buflen; /* amount of data currently in buffer */
137 size_t bufpos; /* current read offset in buffer */
138 int eof; /* end-of-file flag */
139 int error; /* error flag */
140 size_t chunksize; /* remaining size of current chunk */
147 * Get next chunk header
150 http_new_chunk(struct httpio *io)
154 if (fetch_getln(io->conn) == -1)
157 if (io->conn->buflen < 2 || !isxdigit((unsigned char)*io->conn->buf))
160 for (p = io->conn->buf; *p && !isspace((unsigned char)*p); ++p) {
163 if (!isxdigit((unsigned char)*p))
165 if (isdigit((unsigned char)*p)) {
166 io->chunksize = io->chunksize * 16 +
169 io->chunksize = io->chunksize * 16 +
170 10 + tolower((unsigned char)*p) - 'a';
176 io->total += io->chunksize;
177 if (io->chunksize == 0)
178 fprintf(stderr, "%s(): end of last chunk\n", __func__);
180 fprintf(stderr, "%s(): new chunk: %lu (%lu)\n",
181 __func__, (unsigned long)io->chunksize,
182 (unsigned long)io->total);
186 return (io->chunksize);
190 * Grow the input buffer to at least len bytes
193 http_growbuf(struct httpio *io, size_t len)
197 if (io->bufsize >= len)
200 if ((tmp = realloc(io->buf, len)) == NULL)
208 * Fill the input buffer, do chunk decoding on the fly
211 http_fillbuf(struct httpio *io, size_t len)
221 /* not chunked: just fetch the requested amount */
222 if (io->chunked == 0) {
223 if (http_growbuf(io, len) == -1)
225 if ((nbytes = fetch_read(io->conn, io->buf, len)) == -1) {
234 /* chunked, but we ran out: get the next chunk header */
235 if (io->chunksize == 0) {
236 switch (http_new_chunk(io)) {
246 /* fetch the requested amount, but no more than the current chunk */
247 if (len > io->chunksize)
249 if (http_growbuf(io, len) == -1)
251 if ((nbytes = fetch_read(io->conn, io->buf, len)) == -1) {
257 io->chunksize -= nbytes;
259 if (io->chunksize == 0) {
260 if (fetch_read(io->conn, &ch, 1) != 1 || ch != '\r' ||
261 fetch_read(io->conn, &ch, 1) != 1 || ch != '\n')
272 http_readfn(void *v, char *buf, int len)
274 struct httpio *io = (struct httpio *)v;
283 if (!io->buf || io->bufpos == io->buflen) {
284 if ((rlen = http_fillbuf(io, len)) < 0) {
285 if ((errno = io->error) == EINTR)
288 } else if (rlen == 0) {
293 rlen = io->buflen - io->bufpos;
296 memcpy(buf, io->buf + io->bufpos, rlen);
305 http_writefn(void *v, const char *buf, int len)
307 struct httpio *io = (struct httpio *)v;
309 return (fetch_write(io->conn, buf, len));
316 http_closefn(void *v)
318 struct httpio *io = (struct httpio *)v;
321 r = fetch_close(io->conn);
329 * Wrap a file descriptor up
332 http_funopen(conn_t *conn, int chunked)
337 if ((io = calloc(1, sizeof(*io))) == NULL) {
342 io->chunked = chunked;
343 f = funopen(io, http_readfn, http_writefn, NULL, http_closefn);
353 /*****************************************************************************
354 * Helper functions for talking to the server and parsing its replies
367 hdr_transfer_encoding,
368 hdr_www_authenticate,
369 hdr_proxy_authenticate,
372 /* Names of interesting headers */
377 { hdr_content_length, "Content-Length" },
378 { hdr_content_range, "Content-Range" },
379 { hdr_last_modified, "Last-Modified" },
380 { hdr_location, "Location" },
381 { hdr_transfer_encoding, "Transfer-Encoding" },
382 { hdr_www_authenticate, "WWW-Authenticate" },
383 { hdr_proxy_authenticate, "Proxy-Authenticate" },
384 { hdr_unknown, NULL },
388 * Send a formatted line; optionally echo to terminal
391 http_cmd(conn_t *conn, const char *fmt, ...)
399 len = vasprintf(&msg, fmt, ap);
408 r = fetch_putln(conn, msg, len);
420 * Get and parse status line
423 http_get_reply(conn_t *conn)
427 if (fetch_getln(conn) == -1)
430 * A valid status line looks like "HTTP/m.n xyz reason" where m
431 * and n are the major and minor protocol version numbers and xyz
433 * Unfortunately, there are servers out there (NCSA 1.5.1, to name
434 * just one) that do not send a version number, so we can't rely
435 * on finding one, but if we do, insist on it being 1.0 or 1.1.
436 * We don't care about the reason phrase.
438 if (strncmp(conn->buf, "HTTP", 4) != 0)
439 return (HTTP_PROTOCOL_ERROR);
442 if (p[1] != '1' || p[2] != '.' || (p[3] != '0' && p[3] != '1'))
443 return (HTTP_PROTOCOL_ERROR);
447 !isdigit((unsigned char)p[1]) ||
448 !isdigit((unsigned char)p[2]) ||
449 !isdigit((unsigned char)p[3]))
450 return (HTTP_PROTOCOL_ERROR);
452 conn->err = (p[1] - '0') * 100 + (p[2] - '0') * 10 + (p[3] - '0');
457 * Check a header; if the type matches the given string, return a pointer
458 * to the beginning of the value.
461 http_match(const char *str, const char *hdr)
463 while (*str && *hdr &&
464 tolower((unsigned char)*str++) == tolower((unsigned char)*hdr++))
466 if (*str || *hdr != ':')
468 while (*hdr && isspace((unsigned char)*++hdr))
475 * Get the next header and return the appropriate symbolic code. We
476 * need to read one line ahead for checking for a continuation line
477 * belonging to the current header (continuation lines start with
480 * We get called with a fresh line already in the conn buffer, either
481 * from the previous http_next_header() invocation, or, the first
482 * time, from a fetch_getln() performed by our caller.
484 * This stops when we encounter an empty line (we dont read beyond the header
487 * Note that the "headerbuf" is just a place to return the result. Its
488 * contents are not used for the next call. This means that no cleanup
489 * is needed when ie doing another connection, just call the cleanup when
490 * fully done to deallocate memory.
493 /* Limit the max number of continuation lines to some reasonable value */
494 #define HTTP_MAX_CONT_LINES 10
496 /* Place into which to build a header from one or several lines */
498 char *buf; /* buffer */
499 size_t bufsize; /* buffer size */
500 size_t buflen; /* length of buffer contents */
504 init_http_headerbuf(http_headerbuf_t *buf)
512 clean_http_headerbuf(http_headerbuf_t *buf)
516 init_http_headerbuf(buf);
519 /* Remove whitespace at the end of the buffer */
521 http_conn_trimright(conn_t *conn)
523 while (conn->buflen &&
524 isspace((unsigned char)conn->buf[conn->buflen - 1]))
526 conn->buf[conn->buflen] = '\0';
530 http_next_header(conn_t *conn, http_headerbuf_t *hbuf, const char **p)
535 * Have to do the stripping here because of the first line. So
536 * it's done twice for the subsequent lines. No big deal
538 http_conn_trimright(conn);
539 if (conn->buflen == 0)
542 /* Copy the line to the headerbuf */
543 if (hbuf->bufsize < conn->buflen + 1) {
544 if ((hbuf->buf = realloc(hbuf->buf, conn->buflen + 1)) == NULL)
545 return (hdr_syserror);
546 hbuf->bufsize = conn->buflen + 1;
548 strcpy(hbuf->buf, conn->buf);
549 hbuf->buflen = conn->buflen;
552 * Fetch possible continuation lines. Stop at 1st non-continuation
553 * and leave it in the conn buffer
555 for (i = 0; i < HTTP_MAX_CONT_LINES; i++) {
556 if (fetch_getln(conn) == -1)
557 return (hdr_syserror);
560 * Note: we carry on the idea from the previous version
561 * that a pure whitespace line is equivalent to an empty
562 * one (so it's not continuation and will be handled when
563 * we are called next)
565 http_conn_trimright(conn);
566 if (conn->buf[0] != ' ' && conn->buf[0] != "\t"[0])
569 /* Got a continuation line. Concatenate to previous */
570 len = hbuf->buflen + conn->buflen;
571 if (hbuf->bufsize < len + 1) {
573 if ((hbuf->buf = realloc(hbuf->buf, len + 1)) == NULL)
574 return (hdr_syserror);
575 hbuf->bufsize = len + 1;
577 strcpy(hbuf->buf + hbuf->buflen, conn->buf);
578 hbuf->buflen += conn->buflen;
582 * We could check for malformed headers but we don't really care.
583 * A valid header starts with a token immediately followed by a
584 * colon; a token is any sequence of non-control, non-whitespace
585 * characters except "()<>@,;:\\\"{}".
587 for (i = 0; hdr_names[i].num != hdr_unknown; i++)
588 if ((*p = http_match(hdr_names[i].name, hbuf->buf)) != NULL)
589 return (hdr_names[i].num);
591 return (hdr_unknown);
594 /**************************
595 * [Proxy-]Authenticate header parsing
599 * Read doublequote-delimited string into output buffer obuf (allocated
600 * by caller, whose responsibility it is to ensure that it's big enough)
601 * cp points to the first char after the initial '"'
603 * Returns pointer to the first char after the terminating double quote, or
607 http_parse_headerstring(const char *cp, char *obuf)
611 case 0: /* Unterminated string */
614 case '"': /* Ending quote */
629 /* Http auth challenge schemes */
630 typedef enum {HTTPAS_UNKNOWN, HTTPAS_BASIC,HTTPAS_DIGEST} http_auth_schemes_t;
632 /* Data holder for a Basic or Digest challenge. */
634 http_auth_schemes_t scheme;
641 int nc; /* Nonce count */
642 } http_auth_challenge_t;
645 init_http_auth_challenge(http_auth_challenge_t *b)
647 b->scheme = HTTPAS_UNKNOWN;
648 b->realm = b->qop = b->nonce = b->opaque = b->algo = NULL;
649 b->stale = b->nc = 0;
653 clean_http_auth_challenge(http_auth_challenge_t *b)
665 init_http_auth_challenge(b);
668 /* Data holder for an array of challenges offered in an http response. */
669 #define MAX_CHALLENGES 10
671 http_auth_challenge_t *challenges[MAX_CHALLENGES];
672 int count; /* Number of parsed challenges in the array */
673 int valid; /* We did parse an authenticate header */
674 } http_auth_challenges_t;
677 init_http_auth_challenges(http_auth_challenges_t *cs)
680 for (i = 0; i < MAX_CHALLENGES; i++)
681 cs->challenges[i] = NULL;
682 cs->count = cs->valid = 0;
686 clean_http_auth_challenges(http_auth_challenges_t *cs)
689 /* We rely on non-zero pointers being allocated, not on the count */
690 for (i = 0; i < MAX_CHALLENGES; i++) {
691 if (cs->challenges[i] != NULL) {
692 clean_http_auth_challenge(cs->challenges[i]);
693 free(cs->challenges[i]);
696 init_http_auth_challenges(cs);
700 * Enumeration for lexical elements. Separators will be returned as their own
703 typedef enum {HTTPHL_WORD=256, HTTPHL_STRING=257, HTTPHL_END=258,
704 HTTPHL_ERROR = 259} http_header_lex_t;
707 * Determine what kind of token comes next and return possible value
708 * in buf, which is supposed to have been allocated big enough by
709 * caller. Advance input pointer and return element type.
712 http_header_lex(const char **cpp, char *buf)
715 /* Eat initial whitespace */
716 *cpp += strspn(*cpp, " \t");
721 if (**cpp == ',' || **cpp == '=')
722 return (*((*cpp)++));
726 *cpp = http_parse_headerstring(++*cpp, buf);
728 return (HTTPHL_ERROR);
729 return (HTTPHL_STRING);
732 /* Read other token, until separator or whitespace */
733 l = strcspn(*cpp, " \t,=");
734 memcpy(buf, *cpp, l);
737 return (HTTPHL_WORD);
741 * Read challenges from http xxx-authenticate header and accumulate them
742 * in the challenges list structure.
744 * Headers with multiple challenges are specified by rfc2617, but
745 * servers (ie: squid) often send them in separate headers instead,
746 * which in turn is forbidden by the http spec (multiple headers with
747 * the same name are only allowed for pure comma-separated lists, see
750 * We support both approaches anyway
753 http_parse_authenticate(const char *cp, http_auth_challenges_t *cs)
756 http_header_lex_t lex;
757 char *key = malloc(strlen(cp) + 1);
758 char *value = malloc(strlen(cp) + 1);
759 char *buf = malloc(strlen(cp) + 1);
761 if (key == NULL || value == NULL || buf == NULL) {
766 /* In any case we've seen the header and we set the valid bit */
769 /* Need word first */
770 lex = http_header_lex(&cp, key);
771 if (lex != HTTPHL_WORD)
774 /* Loop on challenges */
775 for (; cs->count < MAX_CHALLENGES; cs->count++) {
776 cs->challenges[cs->count] =
777 malloc(sizeof(http_auth_challenge_t));
778 if (cs->challenges[cs->count] == NULL) {
782 init_http_auth_challenge(cs->challenges[cs->count]);
783 if (strcasecmp(key, "basic") == 0) {
784 cs->challenges[cs->count]->scheme = HTTPAS_BASIC;
785 } else if (strcasecmp(key, "digest") == 0) {
786 cs->challenges[cs->count]->scheme = HTTPAS_DIGEST;
788 cs->challenges[cs->count]->scheme = HTTPAS_UNKNOWN;
790 * Continue parsing as basic or digest may
791 * follow, and the syntax is the same for
792 * all. We'll just ignore this one when
793 * looking at the list
797 /* Loop on attributes */
800 lex = http_header_lex(&cp, key);
801 if (lex != HTTPHL_WORD)
805 lex = http_header_lex(&cp, buf);
810 lex = http_header_lex(&cp, value);
811 if (lex != HTTPHL_WORD && lex != HTTPHL_STRING)
814 if (strcasecmp(key, "realm") == 0) {
815 cs->challenges[cs->count]->realm =
817 } else if (strcasecmp(key, "qop") == 0) {
818 cs->challenges[cs->count]->qop =
820 } else if (strcasecmp(key, "nonce") == 0) {
821 cs->challenges[cs->count]->nonce =
823 } else if (strcasecmp(key, "opaque") == 0) {
824 cs->challenges[cs->count]->opaque =
826 } else if (strcasecmp(key, "algorithm") == 0) {
827 cs->challenges[cs->count]->algo =
829 } else if (strcasecmp(key, "stale") == 0) {
830 cs->challenges[cs->count]->stale =
831 strcasecmp(value, "no");
833 /* ignore unknown attributes */
836 /* Comma or Next challenge or End */
837 lex = http_header_lex(&cp, key);
839 * If we get a word here, this is the beginning of the
840 * next challenge. Break the attributes loop
842 if (lex == HTTPHL_WORD)
845 if (lex == HTTPHL_END) {
846 /* End while looking for ',' is normal exit */
851 /* Anything else is an error */
855 } /* End attributes loop */
856 } /* End challenge loop */
859 * Challenges max count exceeded. This really can't happen
860 * with normal data, something's fishy -> error
875 * Parse a last-modified header
878 http_parse_mtime(const char *p, time_t *mtime)
883 strlcpy(locale, setlocale(LC_TIME, NULL), sizeof(locale));
884 setlocale(LC_TIME, "C");
885 r = strptime(p, "%a, %d %b %Y %H:%M:%S GMT", &tm);
887 * Some proxies use UTC in response, but it should still be
888 * parsed. RFC2616 states GMT and UTC are exactly equal for HTTP.
891 r = strptime(p, "%a, %d %b %Y %H:%M:%S UTC", &tm);
892 /* XXX should add support for date-2 and date-3 */
893 setlocale(LC_TIME, locale);
896 DEBUGF("last modified: [%04d-%02d-%02d %02d:%02d:%02d]\n",
897 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
898 tm.tm_hour, tm.tm_min, tm.tm_sec);
899 *mtime = timegm(&tm);
904 * Parse a content-length header
907 http_parse_length(const char *p, off_t *length)
911 for (len = 0; *p && isdigit((unsigned char)*p); ++p)
912 len = len * 10 + (*p - '0');
915 DEBUGF("content length: [%lld]\n", (long long)len);
921 * Parse a content-range header
924 http_parse_range(const char *p, off_t *offset, off_t *length, off_t *size)
926 off_t first, last, len;
928 if (strncasecmp(p, "bytes ", 6) != 0)
935 for (first = 0; *p && isdigit((unsigned char)*p); ++p)
936 first = first * 10 + *p - '0';
939 for (last = 0, ++p; *p && isdigit((unsigned char)*p); ++p)
940 last = last * 10 + *p - '0';
942 if (first > last || *p != '/')
944 for (len = 0, ++p; *p && isdigit((unsigned char)*p); ++p)
945 len = len * 10 + *p - '0';
946 if (*p || len < last - first + 1)
949 DEBUGF("content range: [*/%lld]\n", (long long)len);
952 DEBUGF("content range: [%lld-%lld/%lld]\n",
953 (long long)first, (long long)last, (long long)len);
954 *length = last - first + 1;
962 /*****************************************************************************
963 * Helper functions for authorization
970 http_base64(const char *src)
972 static const char base64[] =
973 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
974 "abcdefghijklmnopqrstuvwxyz"
981 if ((str = malloc(((l + 2) / 3) * 4 + 1)) == NULL)
987 t = (src[0] << 16) | (src[1] << 8) | src[2];
988 dst[0] = base64[(t >> 18) & 0x3f];
989 dst[1] = base64[(t >> 12) & 0x3f];
990 dst[2] = base64[(t >> 6) & 0x3f];
991 dst[3] = base64[(t >> 0) & 0x3f];
998 t = (src[0] << 16) | (src[1] << 8);
999 dst[0] = base64[(t >> 18) & 0x3f];
1000 dst[1] = base64[(t >> 12) & 0x3f];
1001 dst[2] = base64[(t >> 6) & 0x3f];
1008 dst[0] = base64[(t >> 18) & 0x3f];
1009 dst[1] = base64[(t >> 12) & 0x3f];
1010 dst[2] = dst[3] = '=';
1024 * Extract authorization parameters from environment value.
1025 * The value is like scheme:realm:user:pass
1032 } http_auth_params_t;
1035 init_http_auth_params(http_auth_params_t *s)
1037 s->scheme = s->realm = s->user = s->password = NULL;
1041 clean_http_auth_params(http_auth_params_t *s)
1051 init_http_auth_params(s);
1055 http_authfromenv(const char *p, http_auth_params_t *parms)
1059 char *str = strdup(p);
1067 if ((ve = strchr(v, ':')) == NULL)
1071 if ((parms->scheme = strdup(v)) == NULL) {
1077 if ((ve = strchr(v, ':')) == NULL)
1081 if ((parms->realm = strdup(v)) == NULL) {
1087 if ((ve = strchr(v, ':')) == NULL)
1091 if ((parms->user = strdup(v)) == NULL) {
1098 if ((parms->password = strdup(v)) == NULL) {
1105 clean_http_auth_params(parms);
1113 * Digest response: the code to compute the digest is taken from the
1114 * sample implementation in RFC2616
1120 typedef char HASH[HASHLEN];
1121 #define HASHHEXLEN 32
1122 typedef char HASHHEX[HASHHEXLEN+1];
1124 static const char *hexchars = "0123456789abcdef";
1126 CvtHex(IN HASH Bin, OUT HASHHEX Hex)
1131 for (i = 0; i < HASHLEN; i++) {
1132 j = (Bin[i] >> 4) & 0xf;
1133 Hex[i*2] = hexchars[j];
1135 Hex[i*2+1] = hexchars[j];
1137 Hex[HASHHEXLEN] = '\0';
1140 /* calculate H(A1) as per spec */
1144 IN char * pszUserName,
1146 IN char * pszPassword,
1148 IN char * pszCNonce,
1149 OUT HASHHEX SessionKey
1156 MD5Update(&Md5Ctx, pszUserName, strlen(pszUserName));
1157 MD5Update(&Md5Ctx, ":", 1);
1158 MD5Update(&Md5Ctx, pszRealm, strlen(pszRealm));
1159 MD5Update(&Md5Ctx, ":", 1);
1160 MD5Update(&Md5Ctx, pszPassword, strlen(pszPassword));
1161 MD5Final(HA1, &Md5Ctx);
1162 if (strcasecmp(pszAlg, "md5-sess") == 0) {
1165 MD5Update(&Md5Ctx, HA1, HASHLEN);
1166 MD5Update(&Md5Ctx, ":", 1);
1167 MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
1168 MD5Update(&Md5Ctx, ":", 1);
1169 MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
1170 MD5Final(HA1, &Md5Ctx);
1172 CvtHex(HA1, SessionKey);
1175 /* calculate request-digest/response-digest as per HTTP Digest spec */
1178 IN HASHHEX HA1, /* H(A1) */
1179 IN char * pszNonce, /* nonce from server */
1180 IN char * pszNonceCount, /* 8 hex digits */
1181 IN char * pszCNonce, /* client nonce */
1182 IN char * pszQop, /* qop-value: "", "auth", "auth-int" */
1183 IN char * pszMethod, /* method from the request */
1184 IN char * pszDigestUri, /* requested URL */
1185 IN HASHHEX HEntity, /* H(entity body) if qop="auth-int" */
1186 OUT HASHHEX Response /* request-digest or response-digest */
1190 DEBUGF("Calc: HA1[%s] Nonce[%s] qop[%s] method[%s] URI[%s]\n",
1191 HA1, pszNonce, pszQop, pszMethod, pszDigestUri);
1200 MD5Update(&Md5Ctx, pszMethod, strlen(pszMethod));
1201 MD5Update(&Md5Ctx, ":", 1);
1202 MD5Update(&Md5Ctx, pszDigestUri, strlen(pszDigestUri));
1203 if (strcasecmp(pszQop, "auth-int") == 0) {
1204 MD5Update(&Md5Ctx, ":", 1);
1205 MD5Update(&Md5Ctx, HEntity, HASHHEXLEN);
1207 MD5Final(HA2, &Md5Ctx);
1208 CvtHex(HA2, HA2Hex);
1210 // calculate response
1212 MD5Update(&Md5Ctx, HA1, HASHHEXLEN);
1213 MD5Update(&Md5Ctx, ":", 1);
1214 MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
1215 MD5Update(&Md5Ctx, ":", 1);
1217 MD5Update(&Md5Ctx, pszNonceCount, strlen(pszNonceCount));
1218 MD5Update(&Md5Ctx, ":", 1);
1219 MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
1220 MD5Update(&Md5Ctx, ":", 1);
1221 MD5Update(&Md5Ctx, pszQop, strlen(pszQop));
1222 MD5Update(&Md5Ctx, ":", 1);
1224 MD5Update(&Md5Ctx, HA2Hex, HASHHEXLEN);
1225 MD5Final(RespHash, &Md5Ctx);
1226 CvtHex(RespHash, Response);
1230 * Generate/Send a Digest authorization header
1231 * This looks like: [Proxy-]Authorization: credentials
1233 * credentials = "Digest" digest-response
1234 * digest-response = 1#( username | realm | nonce | digest-uri
1235 * | response | [ algorithm ] | [cnonce] |
1236 * [opaque] | [message-qop] |
1237 * [nonce-count] | [auth-param] )
1238 * username = "username" "=" username-value
1239 * username-value = quoted-string
1240 * digest-uri = "uri" "=" digest-uri-value
1241 * digest-uri-value = request-uri ; As specified by HTTP/1.1
1242 * message-qop = "qop" "=" qop-value
1243 * cnonce = "cnonce" "=" cnonce-value
1244 * cnonce-value = nonce-value
1245 * nonce-count = "nc" "=" nc-value
1247 * response = "response" "=" request-digest
1248 * request-digest = <"> 32LHEX <">
1251 http_digest_auth(conn_t *conn, const char *hdr, http_auth_challenge_t *c,
1252 http_auth_params_t *parms, struct url *url)
1255 char noncecount[10];
1257 char *options = NULL;
1259 if (!c->realm || !c->nonce) {
1260 DEBUGF("realm/nonce not set in challenge\n");
1264 c->algo = strdup("");
1266 if (asprintf(&options, "%s%s%s%s",
1267 *c->algo? ",algorithm=" : "", c->algo,
1268 c->opaque? ",opaque=" : "", c->opaque?c->opaque:"") < 0)
1272 c->qop = strdup("");
1277 sprintf(noncecount, "%08x", c->nc);
1278 /* We don't try very hard with the cnonce ... */
1279 sprintf(cnonce, "%x%lx", getpid(), (unsigned long)time(0));
1283 DigestCalcHA1(c->algo, parms->user, c->realm,
1284 parms->password, c->nonce, cnonce, HA1);
1285 DEBUGF("HA1: [%s]\n", HA1);
1287 DigestCalcResponse(HA1, c->nonce, noncecount, cnonce, c->qop,
1288 "GET", url->doc, "", digest);
1291 r = http_cmd(conn, "%s: Digest username=\"%s\",realm=\"%s\","
1292 "nonce=\"%s\",uri=\"%s\",response=\"%s\","
1293 "qop=\"auth\", cnonce=\"%s\", nc=%s%s",
1294 hdr, parms->user, c->realm,
1295 c->nonce, url->doc, digest,
1296 cnonce, noncecount, options);
1298 r = http_cmd(conn, "%s: Digest username=\"%s\",realm=\"%s\","
1299 "nonce=\"%s\",uri=\"%s\",response=\"%s\"%s",
1300 hdr, parms->user, c->realm,
1301 c->nonce, url->doc, digest, options);
1309 * Encode username and password
1312 http_basic_auth(conn_t *conn, const char *hdr, const char *usr, const char *pwd)
1317 DEBUGF("basic: usr: [%s]\n", usr);
1318 DEBUGF("basic: pwd: [%s]\n", pwd);
1319 if (asprintf(&upw, "%s:%s", usr, pwd) == -1)
1321 auth = http_base64(upw);
1325 r = http_cmd(conn, "%s: Basic %s", hdr, auth);
1331 * Chose the challenge to answer and call the appropriate routine to
1332 * produce the header.
1335 http_authorize(conn_t *conn, const char *hdr, http_auth_challenges_t *cs,
1336 http_auth_params_t *parms, struct url *url)
1338 http_auth_challenge_t *digest = NULL;
1341 /* If user or pass are null we're not happy */
1342 if (!parms->user || !parms->password) {
1343 DEBUGF("NULL usr or pass\n");
1347 /* Look for a Digest */
1348 for (i = 0; i < cs->count; i++) {
1349 if (cs->challenges[i]->scheme == HTTPAS_DIGEST)
1350 digest = cs->challenges[i];
1353 /* Error if "Digest" was specified and there is no Digest challenge */
1355 (parms->scheme && strcasecmp(parms->scheme, "digest") == 0)) {
1356 DEBUGF("Digest auth in env, not supported by peer\n");
1360 * If "basic" was specified in the environment, or there is no Digest
1361 * challenge, do the basic thing. Don't need a challenge for this,
1362 * so no need to check basic!=NULL
1365 (parms->scheme && strcasecmp(parms->scheme, "basic") == 0))
1366 return (http_basic_auth(conn,hdr,parms->user,parms->password));
1368 /* Else, prefer digest. We just checked that it's not NULL */
1369 return (http_digest_auth(conn, hdr, digest, parms, url));
1372 /*****************************************************************************
1373 * Helper functions for connecting to a server or proxy
1377 * Connect to the correct HTTP server or proxy.
1380 http_connect(struct url *URL, struct url *purl, const char *flags)
1385 http_headerbuf_t headerbuf;
1397 verbose = CHECK_FLAG('v');
1398 if (CHECK_FLAG('4'))
1401 else if (CHECK_FLAG('6'))
1405 curl = (purl != NULL) ? purl : URL;
1407 if ((conn = fetch_connect(curl->host, curl->port, af, verbose)) == NULL)
1408 /* fetch_connect() has already set an error code */
1410 init_http_headerbuf(&headerbuf);
1411 if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0 && purl) {
1412 http_cmd(conn, "CONNECT %s:%d HTTP/1.1",
1413 URL->host, URL->port);
1414 http_cmd(conn, "Host: %s:%d",
1415 URL->host, URL->port);
1417 if (http_get_reply(conn) != HTTP_OK) {
1418 http_seterr(conn->err);
1421 /* Read and discard the rest of the proxy response */
1422 if (fetch_getln(conn) < 0) {
1427 switch ((h = http_next_header(conn, &headerbuf, &p))) {
1432 http_seterr(HTTP_PROTOCOL_ERROR);
1437 } while (h > hdr_end);
1439 if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0 &&
1440 fetch_ssl(conn, URL, verbose) == -1) {
1448 setsockopt(conn->sd, IPPROTO_TCP, TCP_NOPUSH, &val, sizeof(val));
1450 clean_http_headerbuf(&headerbuf);
1454 clean_http_headerbuf(&headerbuf);
1461 http_get_proxy(struct url * url, const char *flags)
1466 if (flags != NULL && strchr(flags, 'd') != NULL)
1468 if (fetch_no_proxy_match(url->host))
1470 if (((p = getenv("HTTP_PROXY")) || (p = getenv("http_proxy"))) &&
1471 *p && (purl = fetchParseURL(p))) {
1473 strcpy(purl->scheme, SCHEME_HTTP);
1475 purl->port = fetch_default_proxy_port(purl->scheme);
1476 if (strcasecmp(purl->scheme, SCHEME_HTTP) == 0)
1484 http_print_html(FILE *out, FILE *in)
1491 while ((line = fgetln(in, &len)) != NULL) {
1492 while (len && isspace((unsigned char)line[len - 1]))
1494 for (p = q = line; q < line + len; ++q) {
1495 if (comment && *q == '-') {
1496 if (q + 2 < line + len &&
1497 strcmp(q, "-->") == 0) {
1501 } else if (tag && !comment && *q == '>') {
1504 } else if (!tag && *q == '<') {
1506 fwrite(p, q - p, 1, out);
1508 if (q + 3 < line + len &&
1509 strcmp(q, "<!--") == 0) {
1516 fwrite(p, q - p, 1, out);
1522 /*****************************************************************************
1527 http_request(struct url *URL, const char *op, struct url_stat *us,
1528 struct url *purl, const char *flags)
1531 return (http_request_body(URL, op, us, purl, flags, NULL, NULL));
1535 * Send a request and process the reply
1537 * XXX This function is way too long, the do..while loop should be split
1538 * XXX off into a separate function.
1541 http_request_body(struct url *URL, const char *op, struct url_stat *us,
1542 struct url *purl, const char *flags, const char *content_type,
1546 char hbuf[MAXHOSTNAMELEN + 7], *host;
1548 struct url *url, *new;
1549 int chunked, direct, ims, noredirect, verbose;
1551 off_t offset, clength, length, size;
1556 struct tm *timestruct;
1557 http_headerbuf_t headerbuf;
1558 http_auth_challenges_t server_challenges;
1559 http_auth_challenges_t proxy_challenges;
1562 /* The following calls don't allocate anything */
1563 init_http_headerbuf(&headerbuf);
1564 init_http_auth_challenges(&server_challenges);
1565 init_http_auth_challenges(&proxy_challenges);
1567 direct = CHECK_FLAG('d');
1568 noredirect = CHECK_FLAG('A');
1569 verbose = CHECK_FLAG('v');
1570 ims = CHECK_FLAG('i');
1572 if (direct && purl) {
1577 /* try the provided URL first */
1583 e = HTTP_PROTOCOL_ERROR;
1595 url->port = fetch_default_port(url->scheme);
1597 /* were we redirected to an FTP URL? */
1598 if (purl == NULL && strcmp(url->scheme, SCHEME_FTP) == 0) {
1599 if (strcmp(op, "GET") == 0)
1600 return (ftp_request(url, "RETR", us, purl, flags));
1601 else if (strcmp(op, "HEAD") == 0)
1602 return (ftp_request(url, "STAT", us, purl, flags));
1605 /* connect to server or proxy */
1606 if ((conn = http_connect(url, purl, flags)) == NULL)
1609 /* append port number only if necessary */
1611 if (url->port != fetch_default_port(url->scheme)) {
1612 snprintf(hbuf, sizeof(hbuf), "%s:%d", host, url->port);
1618 fetch_info("requesting %s://%s%s",
1619 url->scheme, host, url->doc);
1620 if (purl && strcasecmp(URL->scheme, SCHEME_HTTPS) != 0) {
1621 http_cmd(conn, "%s %s://%s%s HTTP/1.1",
1622 op, url->scheme, host, url->doc);
1624 http_cmd(conn, "%s %s HTTP/1.1",
1628 if (ims && url->ims_time) {
1629 timestruct = gmtime((time_t *)&url->ims_time);
1630 (void)strftime(timebuf, 80, "%a, %d %b %Y %T GMT",
1633 fetch_info("If-Modified-Since: %s", timebuf);
1634 http_cmd(conn, "If-Modified-Since: %s", timebuf);
1637 http_cmd(conn, "Host: %s", host);
1640 * Proxy authorization: we only send auth after we received
1641 * a 407 error. We do not first try basic anyway (changed
1642 * when support was added for digest-auth)
1644 if (purl && proxy_challenges.valid) {
1645 http_auth_params_t aparams;
1646 init_http_auth_params(&aparams);
1647 if (*purl->user || *purl->pwd) {
1648 aparams.user = strdup(purl->user);
1649 aparams.password = strdup(purl->pwd);
1650 } else if ((p = getenv("HTTP_PROXY_AUTH")) != NULL &&
1652 if (http_authfromenv(p, &aparams) < 0) {
1653 http_seterr(HTTP_NEED_PROXY_AUTH);
1656 } else if (fetch_netrc_auth(purl) == 0) {
1657 aparams.user = strdup(purl->user);
1658 aparams.password = strdup(purl->pwd);
1660 http_authorize(conn, "Proxy-Authorization",
1661 &proxy_challenges, &aparams, url);
1662 clean_http_auth_params(&aparams);
1666 * Server authorization: we never send "a priori"
1667 * Basic auth, which used to be done if user/pass were
1668 * set in the url. This would be weird because we'd send the
1669 * password in the clear even if Digest is finally to be
1670 * used (it would have made more sense for the
1671 * pre-digest version to do this when Basic was specified
1672 * in the environment)
1674 if (server_challenges.valid) {
1675 http_auth_params_t aparams;
1676 init_http_auth_params(&aparams);
1677 if (*url->user || *url->pwd) {
1678 aparams.user = strdup(url->user);
1679 aparams.password = strdup(url->pwd);
1680 } else if ((p = getenv("HTTP_AUTH")) != NULL &&
1682 if (http_authfromenv(p, &aparams) < 0) {
1683 http_seterr(HTTP_NEED_AUTH);
1686 } else if (fetch_netrc_auth(url) == 0) {
1687 aparams.user = strdup(url->user);
1688 aparams.password = strdup(url->pwd);
1689 } else if (fetchAuthMethod &&
1690 fetchAuthMethod(url) == 0) {
1691 aparams.user = strdup(url->user);
1692 aparams.password = strdup(url->pwd);
1694 http_seterr(HTTP_NEED_AUTH);
1697 http_authorize(conn, "Authorization",
1698 &server_challenges, &aparams, url);
1699 clean_http_auth_params(&aparams);
1703 if ((p = getenv("HTTP_ACCEPT")) != NULL) {
1705 http_cmd(conn, "Accept: %s", p);
1707 http_cmd(conn, "Accept: */*");
1709 if ((p = getenv("HTTP_REFERER")) != NULL && *p != '\0') {
1710 if (strcasecmp(p, "auto") == 0)
1711 http_cmd(conn, "Referer: %s://%s%s",
1712 url->scheme, host, url->doc);
1714 http_cmd(conn, "Referer: %s", p);
1716 if ((p = getenv("HTTP_USER_AGENT")) != NULL) {
1717 /* no User-Agent if defined but empty */
1719 http_cmd(conn, "User-Agent: %s", p);
1721 /* default User-Agent */
1722 http_cmd(conn, "User-Agent: %s " _LIBFETCH_VER,
1725 if (url->offset > 0)
1726 http_cmd(conn, "Range: bytes=%lld-", (long long)url->offset);
1727 http_cmd(conn, "Connection: close");
1730 body_len = strlen(body);
1731 http_cmd(conn, "Content-Length: %zu", body_len);
1732 if (content_type != NULL)
1733 http_cmd(conn, "Content-Type: %s", content_type);
1739 fetch_write(conn, body, body_len);
1742 * Force the queued request to be dispatched. Normally, one
1743 * would do this with shutdown(2) but squid proxies can be
1744 * configured to disallow such half-closed connections. To
1745 * be compatible with such configurations, fiddle with socket
1746 * options to force the pending data to be written.
1749 setsockopt(conn->sd, IPPROTO_TCP, TCP_NOPUSH, &val,
1752 setsockopt(conn->sd, IPPROTO_TCP, TCP_NODELAY, &val,
1756 switch (http_get_reply(conn)) {
1759 case HTTP_NOT_MODIFIED:
1762 case HTTP_MOVED_PERM:
1763 case HTTP_MOVED_TEMP:
1764 case HTTP_TEMP_REDIRECT:
1765 case HTTP_PERM_REDIRECT:
1766 case HTTP_SEE_OTHER:
1767 case HTTP_USE_PROXY:
1769 * Not so fine, but we still have to read the
1770 * headers to get the new location.
1773 case HTTP_NEED_AUTH:
1774 if (server_challenges.valid) {
1776 * We already sent out authorization code,
1777 * so there's nothing more we can do.
1779 http_seterr(conn->err);
1782 /* try again, but send the password this time */
1784 fetch_info("server requires authorization");
1786 case HTTP_NEED_PROXY_AUTH:
1787 if (proxy_challenges.valid) {
1789 * We already sent our proxy
1790 * authorization code, so there's
1791 * nothing more we can do. */
1792 http_seterr(conn->err);
1795 /* try again, but send the password this time */
1797 fetch_info("proxy requires authorization");
1799 case HTTP_BAD_RANGE:
1801 * This can happen if we ask for 0 bytes because
1802 * we already have the whole file. Consider this
1803 * a success for now, and check sizes later.
1806 case HTTP_PROTOCOL_ERROR:
1812 http_seterr(conn->err);
1815 /* fall through so we can get the full error message */
1818 /* get headers. http_next_header expects one line readahead */
1819 if (fetch_getln(conn) == -1) {
1824 switch ((h = http_next_header(conn, &headerbuf, &p))) {
1829 http_seterr(HTTP_PROTOCOL_ERROR);
1831 case hdr_content_length:
1832 http_parse_length(p, &clength);
1834 case hdr_content_range:
1835 http_parse_range(p, &offset, &length, &size);
1837 case hdr_last_modified:
1838 http_parse_mtime(p, &mtime);
1841 if (!HTTP_REDIRECT(conn->err))
1844 * if the A flag is set, we don't follow
1845 * temporary redirects.
1848 conn->err != HTTP_MOVED_PERM &&
1849 conn->err != HTTP_PERM_REDIRECT &&
1850 conn->err != HTTP_USE_PROXY) {
1857 fetch_info("%d redirect to %s",
1861 new = fetchMakeURL(url->scheme, url->host,
1862 url->port, p, url->user, url->pwd);
1864 new = fetchParseURL(p);
1866 /* XXX should set an error code */
1867 DEBUGF("failed to parse new URL\n");
1871 /* Only copy credentials if the host matches */
1872 if (strcmp(new->host, url->host) == 0 &&
1873 !*new->user && !*new->pwd) {
1874 strcpy(new->user, url->user);
1875 strcpy(new->pwd, url->pwd);
1877 new->offset = url->offset;
1878 new->length = url->length;
1879 new->ims_time = url->ims_time;
1881 case hdr_transfer_encoding:
1883 chunked = (strcasecmp(p, "chunked") == 0);
1885 case hdr_www_authenticate:
1886 if (conn->err != HTTP_NEED_AUTH)
1888 if (http_parse_authenticate(p, &server_challenges) == 0)
1891 case hdr_proxy_authenticate:
1892 if (conn->err != HTTP_NEED_PROXY_AUTH)
1894 if (http_parse_authenticate(p, &proxy_challenges) == 0)
1903 } while (h > hdr_end);
1905 /* we need to provide authentication */
1906 if (conn->err == HTTP_NEED_AUTH ||
1907 conn->err == HTTP_NEED_PROXY_AUTH) {
1909 if ((conn->err == HTTP_NEED_AUTH &&
1910 !server_challenges.valid) ||
1911 (conn->err == HTTP_NEED_PROXY_AUTH &&
1912 !proxy_challenges.valid)) {
1913 /* 401/7 but no www/proxy-authenticate ?? */
1914 DEBUGF("%03d without auth header\n", conn->err);
1922 /* requested range not satisfiable */
1923 if (conn->err == HTTP_BAD_RANGE) {
1924 if (url->offset > 0 && url->length == 0) {
1925 /* asked for 0 bytes; fake it */
1926 offset = url->offset;
1928 conn->err = HTTP_OK;
1931 http_seterr(conn->err);
1936 /* we have a hit or an error */
1937 if (conn->err == HTTP_OK
1938 || conn->err == HTTP_NOT_MODIFIED
1939 || conn->err == HTTP_PARTIAL
1940 || HTTP_ERROR(conn->err))
1943 /* all other cases: we got a redirect */
1945 clean_http_auth_challenges(&server_challenges);
1949 DEBUGF("redirect with no new location\n");
1957 /* we failed, or ran out of retries */
1963 DEBUGF("offset %lld, length %lld, size %lld, clength %lld\n",
1964 (long long)offset, (long long)length,
1965 (long long)size, (long long)clength);
1967 if (conn->err == HTTP_NOT_MODIFIED) {
1968 http_seterr(HTTP_NOT_MODIFIED);
1972 /* check for inconsistencies */
1973 if (clength != -1 && length != -1 && clength != length) {
1974 http_seterr(HTTP_PROTOCOL_ERROR);
1980 length = offset + clength;
1981 if (length != -1 && size != -1 && length != size) {
1982 http_seterr(HTTP_PROTOCOL_ERROR);
1991 us->atime = us->mtime = mtime;
1995 if (URL->offset > 0 && offset > URL->offset) {
1996 http_seterr(HTTP_PROTOCOL_ERROR);
2000 /* report back real offset and size */
2001 URL->offset = offset;
2002 URL->length = clength;
2004 /* wrap it up in a FILE */
2005 if ((f = http_funopen(conn, chunked)) == NULL) {
2015 if (HTTP_ERROR(conn->err)) {
2016 http_print_html(stderr, f);
2020 clean_http_headerbuf(&headerbuf);
2021 clean_http_auth_challenges(&server_challenges);
2022 clean_http_auth_challenges(&proxy_challenges);
2032 clean_http_headerbuf(&headerbuf);
2033 clean_http_auth_challenges(&server_challenges);
2034 clean_http_auth_challenges(&proxy_challenges);
2039 /*****************************************************************************
2044 * Retrieve and stat a file by HTTP
2047 fetchXGetHTTP(struct url *URL, struct url_stat *us, const char *flags)
2049 return (http_request(URL, "GET", us, http_get_proxy(URL, flags), flags));
2053 * Retrieve a file by HTTP
2056 fetchGetHTTP(struct url *URL, const char *flags)
2058 return (fetchXGetHTTP(URL, NULL, flags));
2062 * Store a file by HTTP
2065 fetchPutHTTP(struct url *URL __unused, const char *flags __unused)
2067 warnx("fetchPutHTTP(): not implemented");
2072 * Get an HTTP document's metadata
2075 fetchStatHTTP(struct url *URL, struct url_stat *us, const char *flags)
2079 f = http_request(URL, "HEAD", us, http_get_proxy(URL, flags), flags);
2090 fetchListHTTP(struct url *url __unused, const char *flags __unused)
2092 warnx("fetchListHTTP(): not implemented");
2097 fetchReqHTTP(struct url *URL, const char *method, const char *flags,
2098 const char *content_type, const char *body)
2101 return (http_request_body(URL, method, NULL, http_get_proxy(URL, flags),
2102 flags, content_type, body));