NancyFx / Nancy

Lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono
http://nancyfx.org
MIT License
7.16k stars 1.47k forks source link

SELF HOST: Support weak and strong wildcards in URL prefixes #2978

Open vradarserver opened 4 years ago

vradarserver commented 4 years ago

Prerequisites

Description

The Nancy.Hosting.Self library supports the rewriting of localhost URIs to wildcard URL prefixes. At the moment the rewrite feature only supports the use of the strong wildcard (http://+:etc).

There are occasions where you want to guarantee that you only pick up requests for which no other application has registered a matching prefix. In order to do this Nancy needs to rewrite the localhost URI using the weak wildcard (http://*:etc).

This pull request adds a new property to HostConfiguration called UseWeakWildcard. The property defaults to false. When it is false behaviour remains unchanged, the strong wildcard is used when deriving URL prefixes from localhost URIs. However, when it is set to true the weak wildcard gets used instead.

There are three new unit tests that show:

  1. If you do nothing then the strong wildcard is used, as per current behaviour.
  2. If you explicitly clear UseWeakWildcard then the strong wildcard is used.
  3. If you set UseWeakWildcard then the weak wildcard is used.
dnfclas commented 4 years ago

CLA assistant check
All CLA requirements met.