Skip to content

Commit

Permalink
removed archaical package
Browse files Browse the repository at this point in the history
  • Loading branch information
flrdv committed Apr 26, 2024
1 parent e20ef64 commit db6f0dc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 26 deletions.
13 changes: 0 additions & 13 deletions internal/httpchars/chars.go

This file was deleted.

15 changes: 8 additions & 7 deletions internal/protocol/http1/serializer.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package http1

import (
"fmt"
"github.com/indigo-web/indigo/http"
"github.com/indigo-web/indigo/http/cookie"
"github.com/indigo-web/indigo/http/headers"
"github.com/indigo-web/indigo/http/method"
"github.com/indigo-web/indigo/http/proto"
"github.com/indigo-web/indigo/http/status"
"github.com/indigo-web/indigo/internal/httpchars"
"github.com/indigo-web/indigo/internal/response"
"github.com/indigo-web/utils/strcomp"
"github.com/indigo-web/utils/uf"
"io"
"log"
"strconv"
Expand All @@ -22,6 +21,7 @@ const (
transferEncoding = "Transfer-Encoding: "
contentLength = "Content-Length: "
setCookie = "Set-Cookie: "
crlf = "\r\n"
)

// minimalFileBuffSize defines the minimal size of the file buffer. In case it's less
Expand Down Expand Up @@ -243,8 +243,8 @@ func (d *Serializer) writeChunkedBody(r io.Reader, writer Writer) error {
// offset for it
blankSpace := hexValueOffset - len(buff)
copy(d.fileBuff[blankSpace:], buff)
copy(d.fileBuff[hexValueOffset:], httpchars.CRLF)
copy(d.fileBuff[buffOffset+n:], httpchars.CRLF)
copy(d.fileBuff[hexValueOffset:], crlf)
copy(d.fileBuff[buffOffset+n:], crlf)

if err := writer.Write(d.fileBuff[blankSpace : buffOffset+n+crlfSize]); err != nil {
return status.ErrCloseConnection
Expand Down Expand Up @@ -346,11 +346,11 @@ func (d *Serializer) sp() {
}

func (d *Serializer) colonsp() {
d.buff = append(d.buff, httpchars.COLONSP...)
d.buff = append(d.buff, ':', ' ')
}

func (d *Serializer) crlf() {
d.buff = append(d.buff, httpchars.CRLF...)
d.buff = append(d.buff, crlf...)
}

func (d *Serializer) clear() {
Expand Down Expand Up @@ -389,7 +389,8 @@ func processDefaultHeaders(hdrs map[string]string) defaultHeaders {
}

func renderHeader(key, value string) string {
return key + httpchars.COLONSP + value + uf.B2S(httpchars.CRLF)
// this is done once at serializer construction, so pretty much acceptable
return fmt.Sprintf("%s: %s\r\n", key, value)
}

type defaultHeader struct {
Expand Down
11 changes: 5 additions & 6 deletions router/inbuilt/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package inbuilt
import (
"github.com/indigo-web/indigo/http"
"github.com/indigo-web/indigo/http/headers"
"github.com/indigo-web/indigo/internal/httpchars"
"strings"
)

Expand All @@ -20,11 +19,11 @@ func traceResponse(respond *http.Response, messageBody []byte) *http.Response {

func renderHTTPRequest(request *http.Request, buff []byte) []byte {
buff = append(buff, request.Method.String()...)
buff = append(buff, httpchars.SP...)
buff = append(buff, ' ')
buff = requestURI(request, buff)
buff = append(buff, httpchars.SP...)
buff = append(buff, ' ')
buff = append(buff, strings.TrimSpace(request.Proto.String())...)
buff = append(buff, httpchars.CRLF...)
buff = append(buff, "\r\n"...)
buff = requestHeaders(request.Headers, buff)
buff = append(buff, "Content-Length: 0\r\n\r\n"...)

Expand All @@ -44,8 +43,8 @@ func requestURI(request *http.Request, buff []byte) []byte {

func requestHeaders(hdrs headers.Headers, buff []byte) []byte {
for _, pair := range hdrs.Unwrap() {
buff = append(append(buff, pair.Key...), httpchars.COLONSP...)
buff = append(append(buff, pair.Value...), httpchars.CRLF...)
buff = append(append(buff, pair.Key...), ": "...)
buff = append(append(buff, pair.Value...), "\r\n"...)
}

return buff
Expand Down

0 comments on commit db6f0dc

Please sign in to comment.