Skip to content

Commit

Permalink
fix: remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
byene0923 committed Aug 1, 2022
1 parent 17855b8 commit bbb0b2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
28 changes: 13 additions & 15 deletions pkg/app/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ import (
"context"
"crypto/rand"
"fmt"
"github.com/cloudwego/hertz/internal/bytesconv"
"github.com/cloudwego/hertz/internal/bytestr"
"github.com/cloudwego/hertz/internal/nocopy"
"github.com/cloudwego/hertz/pkg/common/bytebufferpool"
"github.com/cloudwego/hertz/pkg/common/compress"
"github.com/cloudwego/hertz/pkg/common/errors"
"github.com/cloudwego/hertz/pkg/common/hlog"
"github.com/cloudwego/hertz/pkg/common/utils"
"github.com/cloudwego/hertz/pkg/network"
"github.com/cloudwego/hertz/pkg/protocol"
"github.com/cloudwego/hertz/pkg/protocol/consts"
"html"
"io"
"io/ioutil"
Expand All @@ -69,6 +58,17 @@ import (
"strings"
"sync"
"time"
"github.com/cloudwego/hertz/internal/bytesconv"
"github.com/cloudwego/hertz/internal/bytestr"
"github.com/cloudwego/hertz/internal/nocopy"
"github.com/cloudwego/hertz/pkg/common/bytebufferpool"
"github.com/cloudwego/hertz/pkg/common/compress"
"github.com/cloudwego/hertz/pkg/common/errors"
"github.com/cloudwego/hertz/pkg/common/hlog"
"github.com/cloudwego/hertz/pkg/common/utils"
"github.com/cloudwego/hertz/pkg/network"
"github.com/cloudwego/hertz/pkg/protocol"
"github.com/cloudwego/hertz/pkg/protocol/consts"
)

var (
Expand Down Expand Up @@ -1416,7 +1416,6 @@ func (r *smallRangeReader) Read(p []byte) (int, error) {
if r.IsMultiRange() && !r.he {
multiRangeBodyEnd(&r.buf, r.boundary)
r.he = true
cLen = len(p[cPos:])
n = copy(p[cPos:], r.buf)
if len(r.buf) > len(p[cPos:]) {
r.buf = r.buf[n:]
Expand Down Expand Up @@ -1657,7 +1656,6 @@ func (r *bigRangeReader) Read(p []byte) (int, error) {
if r.IsMultiRange() && !r.he {
multiRangeBodyEnd(&r.buf, r.boundary)
r.he = true
cLen = len(p[cPos:])
n = copy(p[cPos:], r.buf)
if len(r.buf) > len(p[cPos:]) {
r.buf = r.buf[n:]
Expand Down Expand Up @@ -1760,13 +1758,13 @@ func multiRangeLength(sta, end []int, cl int, ct, bd string) int {

func multiRangeBodyHeader(b *[]byte, sta, end, size int, ct, boundary string, hf bool) {
if !hf {
*b = append(*b, bytesconv.S2b(fmt.Sprintf("\r\n"))...)
*b = append(*b, bytesconv.S2b("\r\n")...)
}
*b = append(*b, bytesconv.S2b(fmt.Sprintf("--%s\r\n", boundary))...)
*b = append(*b, bytesconv.S2b(fmt.Sprintf("%s: %s\r\n", consts.HeaderContentRange,
fmt.Sprintf("bytes %d-%d/%d", sta, end-1, size)))...)
*b = append(*b, bytesconv.S2b(fmt.Sprintf("%s: %s\r\n", consts.HeaderContentType, ct))...)
*b = append(*b, bytesconv.S2b(fmt.Sprintf("\r\n"))...)
*b = append(*b, bytesconv.S2b("\r\n")...)
}

func multiRangeBodyEnd(b *[]byte, boundary string) {
Expand Down
5 changes: 2 additions & 3 deletions pkg/app/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
"bytes"
"context"
"fmt"
"github.com/cloudwego/hertz/internal/bytesconv"
"io"
"io/ioutil"
"math/rand"
Expand All @@ -54,11 +53,11 @@ import (
"strings"
"testing"
"time"

"github.com/cloudwego/hertz/pkg/common/test/mock"
"github.com/cloudwego/hertz/pkg/protocol"
"github.com/cloudwego/hertz/pkg/protocol/consts"
"github.com/cloudwego/hertz/pkg/protocol/http1/resp"
"github.com/cloudwego/hertz/internal/bytesconv"
)

func TestNewVHostPathRewriter(t *testing.T) {
Expand Down Expand Up @@ -675,7 +674,7 @@ func testFSMultiByteRangeOfRead(t *testing.T, h HandlerFunc, filePath string) {
}

ct := r.Header.Peek(consts.HeaderContentType)
expectedCT := fmt.Sprintf("multipart/byteranges; boundary=")
expectedCT := "multipart/byteranges; boundary="
if !strings.HasPrefix(string(ct), expectedCT) {
t.Fatalf("unexpected content-type %q. Expecting prefix %q. filePath=%q", ct, expectedCT, filePath)
}
Expand Down

0 comments on commit bbb0b2d

Please sign in to comment.