@@ -94,6 +94,131 @@ type TestJSONCookies struct {
94
94
} `json:"cookies"`
95
95
}
96
96
97
+ type MassiveJSONBlob struct {
98
+ Type string `json:"type"`
99
+ Features []struct {
100
+ Type string `json:"type"`
101
+ Properties struct {
102
+ MAPBLKLOT string `json:"MAPBLKLOT"`
103
+ BLKLOT string `json:"BLKLOT"`
104
+ BLOCKNUM string `json:"BLOCK_NUM"`
105
+ LOTNUM string `json:"LOT_NUM"`
106
+ FROMST string `json:"FROM_ST"`
107
+ TOST string `json:"TO_ST"`
108
+ STREET string `json:"STREET"`
109
+ STTYPE interface {} `json:"ST_TYPE"`
110
+ ODDEVEN string `json:"ODD_EVEN"`
111
+ } `json:"properties"`
112
+ Geometry struct {
113
+ Type string `json:"type"`
114
+ Coordinates []struct {
115
+ Num0 []float64 `json:"0,omitempty"`
116
+ Num1 []float64 `json:"1,omitempty"`
117
+ Num2 []float64 `json:"2,omitempty"`
118
+ Num3 []float64 `json:"3,omitempty"`
119
+ Num4 []float64 `json:"4,omitempty"`
120
+ Num5 []float64 `json:"5,omitempty"`
121
+ Num6 []float64 `json:"6,omitempty"`
122
+ Num7 []float64 `json:"7,omitempty"`
123
+ Num8 []float64 `json:"8,omitempty"`
124
+ Num9 []float64 `json:"9,omitempty"`
125
+ Num10 []float64 `json:"10,omitempty"`
126
+ } `json:"-"`
127
+ } `json:"geometry"`
128
+ } `json:"features"`
129
+ }
130
+
131
+ type GithubSelfJSON struct {
132
+ ID int `json:"id"`
133
+ Name string `json:"name"`
134
+ FullName string `json:"full_name"`
135
+ Owner struct {
136
+ Login string `json:"login"`
137
+ ID int `json:"id"`
138
+ AvatarURL string `json:"avatar_url"`
139
+ GravatarID string `json:"gravatar_id"`
140
+ URL string `json:"url"`
141
+ HTMLURL string `json:"html_url"`
142
+ FollowersURL string `json:"followers_url"`
143
+ FollowingURL string `json:"following_url"`
144
+ GistsURL string `json:"gists_url"`
145
+ StarredURL string `json:"starred_url"`
146
+ SubscriptionsURL string `json:"subscriptions_url"`
147
+ OrganizationsURL string `json:"organizations_url"`
148
+ ReposURL string `json:"repos_url"`
149
+ EventsURL string `json:"events_url"`
150
+ ReceivedEventsURL string `json:"received_events_url"`
151
+ Type string `json:"type"`
152
+ SiteAdmin bool `json:"site_admin"`
153
+ } `json:"owner"`
154
+ Private bool `json:"private"`
155
+ HTMLURL string `json:"html_url"`
156
+ Description string `json:"description"`
157
+ Fork bool `json:"fork"`
158
+ URL string `json:"url"`
159
+ ForksURL string `json:"forks_url"`
160
+ KeysURL string `json:"keys_url"`
161
+ CollaboratorsURL string `json:"collaborators_url"`
162
+ TeamsURL string `json:"teams_url"`
163
+ HooksURL string `json:"hooks_url"`
164
+ IssueEventsURL string `json:"issue_events_url"`
165
+ EventsURL string `json:"events_url"`
166
+ AssigneesURL string `json:"assignees_url"`
167
+ BranchesURL string `json:"branches_url"`
168
+ TagsURL string `json:"tags_url"`
169
+ BlobsURL string `json:"blobs_url"`
170
+ GitTagsURL string `json:"git_tags_url"`
171
+ GitRefsURL string `json:"git_refs_url"`
172
+ TreesURL string `json:"trees_url"`
173
+ StatusesURL string `json:"statuses_url"`
174
+ LanguagesURL string `json:"languages_url"`
175
+ StargazersURL string `json:"stargazers_url"`
176
+ ContributorsURL string `json:"contributors_url"`
177
+ SubscribersURL string `json:"subscribers_url"`
178
+ SubscriptionURL string `json:"subscription_url"`
179
+ CommitsURL string `json:"commits_url"`
180
+ GitCommitsURL string `json:"git_commits_url"`
181
+ CommentsURL string `json:"comments_url"`
182
+ IssueCommentURL string `json:"issue_comment_url"`
183
+ ContentsURL string `json:"contents_url"`
184
+ CompareURL string `json:"compare_url"`
185
+ MergesURL string `json:"merges_url"`
186
+ ArchiveURL string `json:"archive_url"`
187
+ DownloadsURL string `json:"downloads_url"`
188
+ IssuesURL string `json:"issues_url"`
189
+ PullsURL string `json:"pulls_url"`
190
+ MilestonesURL string `json:"milestones_url"`
191
+ NotificationsURL string `json:"notifications_url"`
192
+ LabelsURL string `json:"labels_url"`
193
+ ReleasesURL string `json:"releases_url"`
194
+ DeploymentsURL string `json:"deployments_url"`
195
+ CreatedAt time.Time `json:"created_at"`
196
+ UpdatedAt time.Time `json:"updated_at"`
197
+ PushedAt time.Time `json:"pushed_at"`
198
+ GitURL string `json:"git_url"`
199
+ SSHURL string `json:"ssh_url"`
200
+ CloneURL string `json:"clone_url"`
201
+ SvnURL string `json:"svn_url"`
202
+ Homepage string `json:"homepage"`
203
+ Size int `json:"size"`
204
+ StargazersCount int `json:"stargazers_count"`
205
+ WatchersCount int `json:"watchers_count"`
206
+ Language string `json:"language"`
207
+ HasIssues bool `json:"has_issues"`
208
+ HasDownloads bool `json:"has_downloads"`
209
+ HasWiki bool `json:"has_wiki"`
210
+ HasPages bool `json:"has_pages"`
211
+ ForksCount int `json:"forks_count"`
212
+ MirrorURL interface {} `json:"mirror_url"`
213
+ OpenIssuesCount int `json:"open_issues_count"`
214
+ Forks int `json:"forks"`
215
+ OpenIssues int `json:"open_issues"`
216
+ Watchers int `json:"watchers"`
217
+ DefaultBranch string `json:"default_branch"`
218
+ NetworkCount int `json:"network_count"`
219
+ SubscribersCount int `json:"subscribers_count"`
220
+ }
221
+
97
222
func TestGetNoOptions (t * testing.T ) {
98
223
resp , _ := Get ("http://httpbin.org/get" , nil )
99
224
verifyOkResponse (resp , t )
@@ -950,6 +1075,39 @@ func TestGetRedirectSecretHeaderNoCopy(t *testing.T) {
950
1075
951
1076
}
952
1077
1078
+ func TestMassiveJSONFile (t * testing.T ) {
1079
+ if testing .Short () {
1080
+ t .Skip ("Skipping massive JSON file download because short was called" )
1081
+ }
1082
+ resp , err := Get ("https://raw.githubusercontent.com/levigross/sf-city-lots-json/master/citylots.json" , nil )
1083
+ if err != nil {
1084
+ t .Error ("Request to massive JSON blob failed" , err )
1085
+ }
1086
+
1087
+ myjson := & MassiveJSONBlob {}
1088
+
1089
+ if err := resp .JSON (myjson ); err != nil {
1090
+ t .Error ("Unable to serialize massive JSON blob" , err )
1091
+ }
1092
+
1093
+ if myjson .Type != "FeatureCollection" {
1094
+ t .Error ("JSON did not properly serialize" )
1095
+ }
1096
+ }
1097
+
1098
+ func TestGitHubSelfJSON (t * testing.T ) {
1099
+ resp , err := Get ("https://api.github.com/repos/levigross/grequests" , nil )
1100
+ if err != nil {
1101
+ t .Error ("Request to reddit JSON blob failed" , err )
1102
+ }
1103
+
1104
+ myjson := & GithubSelfJSON {}
1105
+
1106
+ if err := resp .JSON (myjson ); err != nil {
1107
+ t .Error ("Unable to serialize reddit JSON blob" , err )
1108
+ }
1109
+ }
1110
+
953
1111
func TestUnlimitedRedirects (t * testing.T ) {
954
1112
srv := httptest .NewServer (http .DefaultServeMux )
955
1113
http .HandleFunc ("/bar" , func (w http.ResponseWriter , req * http.Request ) {
@@ -973,15 +1131,26 @@ func TestAuthStripOnRedirect(t *testing.T) {
973
1131
srv := httptest .NewServer (http .DefaultServeMux )
974
1132
http .HandleFunc ("/test/" , func (w http.ResponseWriter , req * http.Request ) {
975
1133
if req .Header .Get ("Authorization" ) != "" {
976
- http .Error (w , "Found Auth:" , http .StatusInternalServerError )
1134
+ http .Error (w , "Found Auth: " + req . Header . Get ( "Authorization" ) , http .StatusInternalServerError )
977
1135
return
978
1136
}
1137
+
1138
+ if req .Header .Get ("WWW-Authenticate" ) != "" {
1139
+ http .Error (w , "Found Auth: " + req .Header .Get ("WWW-Authenticate" ), http .StatusInternalServerError )
1140
+ return
1141
+ }
1142
+
1143
+ if req .Header .Get ("Proxy-Authorization" ) != "" {
1144
+ http .Error (w , "Found Auth: " + req .Header .Get ("Proxy-Authorization" ), http .StatusInternalServerError )
1145
+ return
1146
+ }
1147
+
979
1148
io .WriteString (w , "OK" )
980
1149
})
981
1150
982
1151
resp , err := Get (srv .URL + "/test" , & RequestOptions {
983
1152
Auth : []string {"one " , "two" },
984
- Headers : map [string ]string {"WWW-Authenticate" : "foo" },
1153
+ Headers : map [string ]string {"WWW-Authenticate" : "foo" , "Proxy-Authorization" : "bar" },
985
1154
})
986
1155
987
1156
if err != nil {
0 commit comments