ok

Claudio Jeker(cje...@diehard.n-r-g.com) on 2021.09.10 12:09:47 +0200:
> On Thu, Sep 09, 2021 at 09:18:04AM -0600, Bob Beck wrote:
> > 
> > ok beck@
> > 
> > On Thu, Sep 09, 2021 at 09:35:51AM +0200, Claudio Jeker wrote:
> > > While Connection: keep-alive should be the default it seems that at least
> > > some of the CA repositories fail to behave like that. Adding back the
> > > Connection header seems to fix this and delta downloads go faster again.
> > > 
> 
> After further inspection of the code and the HTTP/1.1 RFC I came to the
> conclusion that the code is wrong. For HTTP/1.1 the default should be
> keep-alive being on. For non-HTTP/1.1 (aka HTTP/1.0 there is no other 1.X
> spec) keep-alive should be off by default.
> 
> So look at the HTTP protocol header and set keep-alive then. This seems to
> work. Also check for Connection: close. At least one server sends a
> Connection: close header after a bunch of requests.
> 
> So this is a better fix for the keep-alive issue.
> -- 
> :wq Claudio
> 
> Index: http.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/http.c,v
> retrieving revision 1.38
> diff -u -p -r1.38 http.c
> --- http.c    1 Sep 2021 09:39:14 -0000       1.38
> +++ http.c    10 Sep 2021 10:02:12 -0000
> @@ -1053,11 +1053,16 @@ http_request(struct http_connection *con
>  static int
>  http_parse_status(struct http_connection *conn, char *buf)
>  {
> +#define HTTP_11      "HTTP/1.1 "
>       const char *errstr;
>       char *cp, ststr[4];
>       char gerror[200];
>       int status;
>  
> +     /* Check if the protocol is 1.1 and enable keep-alive in that case */
> +     if (strncmp(buf, HTTP_11, strlen(HTTP_11)) == 0)
> +             conn->keep_alive = 1;
> +
>       cp = strchr(buf, ' ');
>       if (cp == NULL) {
>               warnx("Improper response from %s", http_info(conn->host));
> @@ -1226,7 +1231,9 @@ http_parse_header(struct http_connection
>       } else if (strncasecmp(cp, CONNECTION, sizeof(CONNECTION) - 1) == 0) {
>               cp += sizeof(CONNECTION) - 1;
>               cp[strcspn(cp, " \t")] = '\0';
> -             if (strcasecmp(cp, "keep-alive") == 0)
> +             if (strcasecmp(cp, "close") == 0)
> +                     conn->keep_alive = 0;
> +             else if (strcasecmp(cp, "keep-alive") == 0)
>                       conn->keep_alive = 1;
>       } else if (strncasecmp(cp, LAST_MODIFIED,
>           sizeof(LAST_MODIFIED) - 1) == 0) {
> 

Reply via email to