mirror of
https://github.com/soypat/lneto.git
synced 2026-08-21 15:09:05 +00:00
Further improvements to httphi API (#173)
* add Exchange.WriteBodyString * Mux.MaxPathValues and other improvements * Mux PathValue improvemnt and fixes * MuxSlice more method muxing improvements * diagram out interesting approach to form parsing for clanker * refactor RequestParseForm and achieve greatness in API design * explicit naming of headerCapacityKV value in kvBuffer.Reset * fix Mux bug not matching paths correctly; httpraw HTTP V1 naming applied * rename many examples,use httphi in examples,remove useless maxAwaitingConn field * add ipv4.String * add ipv4 UnspecifiedAddr and BroadcastAddr * add ethernet.String
This commit is contained in:
+16
-1
@@ -18,6 +18,12 @@ func IsMulticast(addr [4]byte) bool {
|
||||
return addr[0]&0xf0 == 0xe0
|
||||
}
|
||||
|
||||
// UnspecifiedAddr returns the unspecified address: 0.0.0.0
|
||||
func UnspecifiedAddr() [4]byte { return [4]byte{0, 0, 0, 0} }
|
||||
|
||||
// BroadcastAddr returns the broadcast address: 255.255.255.255
|
||||
func BroadcastAddr() [4]byte { return [4]byte{255, 255, 255, 255} }
|
||||
|
||||
// IsBroadcast reports whether addr is the limited broadcast address
|
||||
// 255.255.255.255 used to address all hosts on the local network segment
|
||||
// as defined in [RFC919]. It does not detect directed (subnet) broadcast
|
||||
@@ -26,7 +32,7 @@ func IsMulticast(addr [4]byte) bool {
|
||||
//
|
||||
// [RFC919]: https://datatracker.ietf.org/doc/html/rfc919
|
||||
func IsBroadcast(addr [4]byte) bool {
|
||||
return addr == [4]byte{255, 255, 255, 255}
|
||||
return addr == BroadcastAddr()
|
||||
}
|
||||
|
||||
// IsLinkLocal reports whether addr is within the IPv4 link-local prefix
|
||||
@@ -113,3 +119,12 @@ func AppendFormatAddr(dst []byte, addr [4]byte) []byte {
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
// String returns the dotted-decimal text representation of an IPv4 address.
|
||||
func String(addr [4]byte) string {
|
||||
// See net/netip's (Addr).string4 pattern.
|
||||
var buf [maxAddrStringLen]byte
|
||||
return string(AppendFormatAddr(buf[:0], addr))
|
||||
}
|
||||
|
||||
const maxAddrStringLen = len("255.255.255.255")
|
||||
|
||||
@@ -10,10 +10,10 @@ func TestAppendFormatAddr(t *testing.T) {
|
||||
addr [4]byte
|
||||
want string
|
||||
}{
|
||||
{addr: [4]byte{0, 0, 0, 0}, want: "0.0.0.0"},
|
||||
{addr: UnspecifiedAddr(), want: "0.0.0.0"},
|
||||
{addr: BroadcastAddr(), want: "255.255.255.255"},
|
||||
{addr: [4]byte{127, 0, 0, 1}, want: "127.0.0.1"},
|
||||
{addr: [4]byte{192, 168, 1, 1}, want: "192.168.1.1"},
|
||||
{addr: [4]byte{255, 255, 255, 255}, want: "255.255.255.255"},
|
||||
{addr: [4]byte{10, 0, 0, 1}, want: "10.0.0.1"},
|
||||
{addr: [4]byte{1, 2, 3, 4}, want: "1.2.3.4"},
|
||||
{addr: [4]byte{100, 99, 9, 0}, want: "100.99.9.0"},
|
||||
|
||||
Reference in New Issue
Block a user