[PATCH] add per-protocol override for HTTP User-Agent

Daniel Lenski dlenski at gmail.com
Sun Dec 17 12:30:52 PST 2017


On Sun, Dec 17, 2017 at 12:21 PM, Daniel Lenski <dlenski at gmail.com> wrote:
> Signed-off-by: Daniel Lenski <dlenski at gmail.com>
> ---
>  http.c                 | 2 +-
>  openconnect-internal.h | 1 +
>  2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/http.c b/http.c
> index 5307d82..2960296 100644
> --- a/http.c
> +++ b/http.c
> @@ -1472,7 +1472,7 @@ void http_common_headers(struct openconnect_info *vpninfo, struct oc_text_buf *b
>                 buf_append(buf, "Host: %s\r\n", vpninfo->hostname);
>         else
>                 buf_append(buf, "Host: %s:%d\r\n", vpninfo->hostname, vpninfo->port);
> -       buf_append(buf, "User-Agent: %s\r\n", vpninfo->useragent);
> +       buf_append(buf, "User-Agent: %s\r\n", vpninfo->proto->override_useragent ? : vpninfo->useragent);
>
>         if (vpninfo->cookies) {
>                 buf_append(buf, "Cookie: ");
> diff --git a/openconnect-internal.h b/openconnect-internal.h
> index 0c0b7d4..a193151 100644
> --- a/openconnect-internal.h
> +++ b/openconnect-internal.h
> @@ -263,6 +263,7 @@ struct vpn_proto {
>         const char *name;
>         const char *pretty_name;
>         const char *description;
> +       const char *override_useragent;
>         unsigned int flags;
>         int (*vpn_close_session)(struct openconnect_info *vpninfo, const char *reason);
>
> --
> 2.7.4
>

This patch is intended to support protocols, like GlobalProtect, which
require a specific User-Agent header value to be set in order to work
correctly.

It could be written in other ways (for example, a callable function to
add the appropriate HTTP header, rather than a fixed string), but in
the absence of any known use for a more complex version, this seems
like the most straightforward approach.

-Dan



More information about the openconnect-devel mailing list