Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
0d8797bf
Commit
0d8797bf
authored
Feb 01, 2010
by
Petar Maymounkov
Committed by
Russ Cox
Feb 01, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: test for ReadReqeust
R=rsc, rsc1 CC=golang-dev
https://golang.org/cl/195068
parent
bea730d1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
0 deletions
+96
-0
readrequest_test.go
src/pkg/http/readrequest_test.go
+96
-0
No files found.
src/pkg/http/readrequest_test.go
0 → 100644
View file @
0d8797bf
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
http
import
(
"bufio"
"bytes"
"fmt"
"io"
"testing"
)
type
reqTest
struct
{
Raw
string
Req
Request
Body
string
}
var
reqTests
=
[]
reqTest
{
// Baseline test; All Request fields included for template use
reqTest
{
"GET http://www.techcrunch.com/ HTTP/1.1
\r\n
"
+
"Host: www.techcrunch.com
\r\n
"
+
"User-Agent: Fake
\r\n
"
+
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
\r\n
"
+
"Accept-Language: en-us,en;q=0.5
\r\n
"
+
"Accept-Encoding: gzip,deflate
\r\n
"
+
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
\r\n
"
+
"Keep-Alive: 300
\r\n
"
+
"Content-Length: 7
\r\n
"
+
"Proxy-Connection: keep-alive
\r\n\r\n
"
+
"abcdef
\n
???"
,
Request
{
Method
:
"GET"
,
RawURL
:
"http://www.techcrunch.com/"
,
URL
:
&
URL
{
Raw
:
"http://www.techcrunch.com/"
,
Scheme
:
"http"
,
RawPath
:
"//www.techcrunch.com/"
,
Authority
:
"www.techcrunch.com"
,
Userinfo
:
""
,
Host
:
"www.techcrunch.com"
,
Path
:
"/"
,
RawQuery
:
""
,
Fragment
:
""
,
},
Proto
:
"HTTP/1.1"
,
ProtoMajor
:
1
,
ProtoMinor
:
1
,
Header
:
map
[
string
]
string
{
"Accept"
:
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
,
"Accept-Language"
:
"en-us,en;q=0.5"
,
"Accept-Encoding"
:
"gzip,deflate"
,
"Accept-Charset"
:
"ISO-8859-1,utf-8;q=0.7,*;q=0.7"
,
"Keep-Alive"
:
"300"
,
"Proxy-Connection"
:
"keep-alive"
,
"Content-Length"
:
"7"
,
},
Close
:
false
,
Host
:
"www.techcrunch.com"
,
Referer
:
""
,
UserAgent
:
"Fake"
,
Form
:
map
[
string
][]
string
{},
},
"abcdef
\n
"
,
},
}
func
TestReadRequest
(
t
*
testing
.
T
)
{
for
i
:=
range
reqTests
{
tt
:=
&
reqTests
[
i
]
var
braw
bytes
.
Buffer
braw
.
WriteString
(
tt
.
Raw
)
req
,
err
:=
ReadRequest
(
bufio
.
NewReader
(
&
braw
))
if
err
!=
nil
{
t
.
Errorf
(
"#%d: %s"
,
i
,
err
)
continue
}
rbody
:=
req
.
Body
req
.
Body
=
nil
diff
(
t
,
fmt
.
Sprintf
(
"#%d Request"
,
i
),
req
,
&
tt
.
Req
)
var
bout
bytes
.
Buffer
if
rbody
!=
nil
{
io
.
Copy
(
&
bout
,
rbody
)
rbody
.
Close
()
}
body
:=
bout
.
String
()
if
body
!=
tt
.
Body
{
t
.
Errorf
(
"#%d: Body = %q want %q"
,
i
,
body
,
tt
.
Body
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment