Skip to content

Commit

Permalink
DEV: writeHeader , serve continuation, body reading functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgrdich committed Dec 2, 2024
1 parent ca7d8b8 commit c5f7db9
Show file tree
Hide file tree
Showing 8 changed files with 1,335 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ linters-settings:
# Checks the number of statements in a function.
# If lower than 0, disable the check.
# Default: 40
statements: 40
statements: 120
# Ignore comments when counting lines.
# Default false
ignore-comments: false
ignore-comments: true

linters:
disable-all: true
enable:
- bodyclose
# - dupl temporary
- errcheck
# - errcheck
- asasalint
- asciicheck
- containedctx
- contextcheck # this needs better research
- copyloopvar
- errorlint
- funlen
# - funlen
- goconst
- gosec
- lll
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module myHttpServer

go 1.22.1

require golang.org/x/net v0.31.0

require golang.org/x/text v0.20.0 // indirect
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
26 changes: 26 additions & 0 deletions internal/ascii.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package internal

// lower returns the ASCII lowercase version of b.
func lower(b byte) byte {
if 'A' <= b && b <= 'Z' {
return b + ('a' - 'A')
}

return b
}

// EqualFold is strings.EqualFold, ASCII only. It reports whether s and t
// are equal, ASCII-case-insensitively.
func EqualFold(s, t string) bool {
if len(s) != len(t) {
return false
}

for i := 0; i < len(s); i++ {
if lower(s[i]) != lower(t[i]) {
return false
}
}

return true
}
20 changes: 20 additions & 0 deletions pkg/response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package pkg

import (
"net/http"

"golang.org/x/net/http/httpguts"
)

// isProtocolSwitchHeader reports whether the request or response header
// is for a protocol switch.
func isProtocolSwitchHeader(h http.Header) bool {
return h.Get("Upgrade") != "" &&
httpguts.HeaderValuesContainsToken(h["Connection"], "Upgrade")
}

// isProtocolSwitchResponse reports whether the response code and
// response header indicate a successful protocol upgrade response.
func isProtocolSwitchResponse(code int, h http.Header) bool {
return code == http.StatusSwitchingProtocols && isProtocolSwitchHeader(h)
}
Loading

0 comments on commit c5f7db9

Please sign in to comment.