@@ -128,30 +128,35 @@ func check(response http.ResponseWriter, req *http.Request) {
128
128
129
129
// 获取传入域名
130
130
if len (req .Form .Get ("domain" )) == 0 {
131
+ response .WriteHeader (400 )
131
132
fmt .Fprintf (response , "No domain specified." )
132
133
return
133
134
}
134
135
domain = req .Form .Get ("domain" )
135
136
// 获取传入文件名
136
137
if len (req .Form .Get ("file" )) == 0 {
138
+ response .WriteHeader (400 )
137
139
fmt .Fprintf (response , "No file specified." )
138
140
return
139
141
}
140
142
file = req .Form .Get ("file" )
141
143
// 获取传入签名
142
144
if len (req .Form .Get ("sign" )) == 0 {
145
+ response .WriteHeader (400 )
143
146
fmt .Fprintf (response , "No sign specified." )
144
147
return
145
148
}
146
149
sign = req .Form .Get ("sign" )
147
150
// 获取传入验证码
148
151
if len (req .Form .Get ("checksum" )) == 0 {
152
+ response .WriteHeader (400 )
149
153
fmt .Fprintf (response , "No checksum specified." )
150
154
return
151
155
}
152
156
checksum = req .Form .Get ("checksum" )
153
157
// 获取传入时间戳
154
158
if len (req .Form .Get ("t" )) == 0 {
159
+ response .WriteHeader (400 )
155
160
fmt .Fprintf (response , "No timestamp specified." )
156
161
return
157
162
}
@@ -162,6 +167,7 @@ func check(response http.ResponseWriter, req *http.Request) {
162
167
if err != nil {
163
168
fmt .Println ("Access from IP:" , ip )
164
169
fmt .Println ("Incoming illegal timestamp:" , t )
170
+ response .WriteHeader (403 )
165
171
fmt .Fprintf (response , "Timestamp not allowed." )
166
172
return
167
173
}
@@ -170,13 +176,15 @@ func check(response http.ResponseWriter, req *http.Request) {
170
176
if expireTime < - timeRange {
171
177
fmt .Println ("Access from IP:" , ip )
172
178
fmt .Println ("Incoming illegal timestamp:" , expireTime )
179
+ response .WriteHeader (403 )
173
180
fmt .Fprintf (response , "Timestamp not allowed." )
174
181
return
175
182
}
176
183
// 校验时间戳是否过期
177
184
if expireTime > timeRange {
178
185
fmt .Println ("Access from IP:" , ip )
179
186
fmt .Println ("Incoming expired access:" , expireTime )
187
+ response .WriteHeader (403 )
180
188
fmt .Fprintf (response , "Timestamp expired." )
181
189
return
182
190
}
@@ -200,6 +208,7 @@ func check(response http.ResponseWriter, req *http.Request) {
200
208
// 检测到重放请求
201
209
fmt .Println ("Access from IP:" , ip )
202
210
fmt .Println ("Incoming repeat access:" , checksum )
211
+ response .WriteHeader (403 )
203
212
fmt .Fprintf (response , "Repeat access." )
204
213
return
205
214
}
@@ -227,13 +236,15 @@ func check(response http.ResponseWriter, req *http.Request) {
227
236
// 获取的域名不存在
228
237
fmt .Println ("Access from IP:" , ip )
229
238
fmt .Println ("Incoming illegal domain:" , domain )
239
+ response .WriteHeader (404 )
230
240
fmt .Fprintf (response , "Domain not exist." )
231
241
return
232
242
}
233
243
if ! checkFile {
234
244
// 获取的文件不存在
235
245
fmt .Println ("Access from IP:" , ip )
236
246
fmt .Println ("Incoming illegal filename:" , file )
247
+ response .WriteHeader (404 )
237
248
fmt .Fprintf (response , "File not exist." )
238
249
return
239
250
}
@@ -246,6 +257,7 @@ func check(response http.ResponseWriter, req *http.Request) {
246
257
// 签名错误
247
258
fmt .Println ("Access from IP:" , ip )
248
259
fmt .Println ("Incoming unauthorized access:" , sign )
260
+ response .WriteHeader (401 )
249
261
fmt .Fprintf (response , "Unauthorized access." )
250
262
}
251
263
}
0 commit comments