diff options
Diffstat (limited to 'src/util/util.c')
-rw-r--r-- | src/util/util.c | 79 |
1 files changed, 51 insertions, 28 deletions
diff --git a/src/util/util.c b/src/util/util.c index 027daf427..3341aa295 100644 --- a/src/util/util.c +++ b/src/util/util.c | |||
@@ -424,6 +424,53 @@ TALER_url_absolute_raw (const char *proto, | |||
424 | 424 | ||
425 | 425 | ||
426 | /** | 426 | /** |
427 | * Find out if an MHD connection is using HTTPS (either | ||
428 | * directly or via proxy). | ||
429 | * | ||
430 | * @param connection MHD connection | ||
431 | * @returns GNUNET_YES if the MHD connection is using https, | ||
432 | * GNUNET_NO if the MHD connection is using http, | ||
433 | * GNUNET_SYSERR if the connection type couldn't be determined | ||
434 | */ | ||
435 | int | ||
436 | TALER_mhd_is_https (struct MHD_Connection *connection) | ||
437 | { | ||
438 | const union MHD_ConnectionInfo *ci; | ||
439 | const union MHD_DaemonInfo *di; | ||
440 | const char *forwarded_proto = MHD_lookup_connection_value (connection, | ||
441 | MHD_HEADER_KIND, | ||
442 | "X-Forwarded-Proto"); | ||
443 | |||
444 | if (NULL != forwarded_proto) | ||
445 | { | ||
446 | if (0 == strcmp (forwarded_proto, "https")) | ||
447 | return GNUNET_YES; | ||
448 | if (0 == strcmp (forwarded_proto, "http")) | ||
449 | return GNUNET_NO; | ||
450 | GNUNET_break (0); | ||
451 | return GNUNET_SYSERR; | ||
452 | } | ||
453 | /* likely not reverse proxy, figure out if we are | ||
454 | http by asking MHD */ | ||
455 | ci = MHD_get_connection_info (connection, MHD_CONNECTION_INFO_DAEMON); | ||
456 | if (NULL == ci) | ||
457 | { | ||
458 | GNUNET_break (0); | ||
459 | return GNUNET_SYSERR; | ||
460 | } | ||
461 | di = MHD_get_daemon_info (ci->daemon, MHD_DAEMON_INFO_FLAGS); | ||
462 | if (NULL == di) | ||
463 | { | ||
464 | GNUNET_break (0); | ||
465 | return GNUNET_SYSERR; | ||
466 | } | ||
467 | if (0 != (di->flags & MHD_USE_TLS)) | ||
468 | return GNUNET_YES; | ||
469 | return GNUNET_NO; | ||
470 | } | ||
471 | |||
472 | |||
473 | /** | ||
427 | * Make an absolute URL for a given MHD connection. | 474 | * Make an absolute URL for a given MHD connection. |
428 | * | 475 | * |
429 | * @param path path of the url | 476 | * @param path path of the url |
@@ -437,42 +484,18 @@ TALER_url_absolute_mhd (struct MHD_Connection *connection, | |||
437 | ...) | 484 | ...) |
438 | { | 485 | { |
439 | /* By default we assume we're running under HTTPS */ | 486 | /* By default we assume we're running under HTTPS */ |
440 | const char *proto = "https"; | 487 | const char *proto; |
441 | const char *forwarded_proto = MHD_lookup_connection_value (connection, | ||
442 | MHD_HEADER_KIND, | ||
443 | "X-Forwarded-Proto"); | ||
444 | const char *host; | 488 | const char *host; |
445 | const char *forwarded_host; | 489 | const char *forwarded_host; |
446 | const char *prefix; | 490 | const char *prefix; |
447 | va_list args; | 491 | va_list args; |
448 | char *result; | 492 | char *result; |
449 | 493 | ||
450 | 494 | if (GNUNET_YES == TALER_mhd_is_https (connection)) | |
451 | if (NULL != forwarded_proto) | 495 | proto = "https"; |
452 | { | ||
453 | proto = forwarded_proto; | ||
454 | } | ||
455 | else | 496 | else |
456 | { | 497 | proto = "http"; |
457 | /* likely not reverse proxy, figure out if we are | ||
458 | http by asking MHD */ | ||
459 | const union MHD_ConnectionInfo *ci; | ||
460 | 498 | ||
461 | ci = MHD_get_connection_info (connection, | ||
462 | MHD_CONNECTION_INFO_DAEMON); | ||
463 | if (NULL != ci) | ||
464 | { | ||
465 | const union MHD_DaemonInfo *di; | ||
466 | |||
467 | di = MHD_get_daemon_info (ci->daemon, | ||
468 | MHD_DAEMON_INFO_FLAGS); | ||
469 | if (NULL != di) | ||
470 | { | ||
471 | if (0 == (di->flags & MHD_USE_TLS)) | ||
472 | proto = "http"; | ||
473 | } | ||
474 | } | ||
475 | } | ||
476 | host = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, "Host"); | 499 | host = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, "Host"); |
477 | forwarded_host = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, | 500 | forwarded_host = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, |
478 | "X-Forwarded-Host"); | 501 | "X-Forwarded-Host"); |