Skip to content

Check for nil host before match?.#841

Merged
sferik merged 1 commit into
httprb:mainfrom
benubois:nil_host
Jul 14, 2026
Merged

Check for nil host before match?.#841
sferik merged 1 commit into
httprb:mainfrom
benubois:nil_host

Conversation

@benubois

Copy link
Copy Markdown
Contributor

When host is nil, I get a NoMethodError: undefined method 'match?' for nil error instead of a RequestError.

Thanks!

@ixti

ixti commented Jun 24, 2026

Copy link
Copy Markdown
Member

Thank you!

@ixti

ixti commented Jun 24, 2026

Copy link
Copy Markdown
Member

After some thinking. While we're at this, we should probably enrich that method in general. According (if I read it correct) to RFC 9110:

Host = uri-host [ ":" port ]; Section 4

uri-host      = <host, see [URI], Section 3.2.2>
port          = <port, see [URI], Section 3.2.3>

Host part is mandatory. And, either way, I think it's at least mandatory in case of "default" ))

So, I think:

  • ":123" (empty host, different port, as in https://:123/foobar) MUST be invalid for default host header
  • "" (empty host, no whitespaces, same port, as in https:///foobar) MUST be invalid as well

cc: @sferik

@sferik sferik merged commit 556f17d into httprb:main Jul 14, 2026
8 checks passed
sferik added a commit that referenced this pull request Jul 14, 2026
Follow-up to #841:
Per RFC 9110 Section 7.2 the Host header requires a non-empty uri-host,
so also reject empty hosts, which previously produced invalid "Host: "
(https:///path) or "Host: :123" (https://:123/path) headers. Also assert
the error message in the nil-host test, matching the whitespace test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants