@@ -104,6 +104,8 @@ func (h *handler) handleRequest(req api.Request, resp api.Response) (next bool,
104104 next , reqCtx = h .testReadBody (req , resp , strings .Repeat ("a" , 4096 ))
105105 case "read_body/request/xlarge" :
106106 next , reqCtx = h .testReadBody (req , resp , strings .Repeat ("a" , 5000 ))
107+ case "get_source_addr" :
108+ next , reqCtx = h .testGetSourceAddr (req , resp , "127.0.0.1" )
107109 default :
108110 fail (resp , "unknown x-httpwasm-test-id" )
109111 }
@@ -214,6 +216,24 @@ func (h *handler) testReadBody(req api.Request, resp api.Response, expectedBody
214216 return true , 0
215217}
216218
219+ func (h * handler ) testGetSourceAddr (req api.Request , resp api.Response , expectedAddr string ) (next bool , reqCtx uint32 ) {
220+ addr := req .GetSourceAddr ()
221+ raw := strings .Split (addr , ":" )
222+ if len (raw ) != 2 {
223+ fail (resp , fmt .Sprintf ("get_source_addr: unknown colon count %s" , req .GetSourceAddr ()))
224+ return
225+ }
226+ if raw [0 ] != expectedAddr {
227+ fail (resp , fmt .Sprintf ("get_source_addr: want %s, have %s" , expectedAddr , req .GetSourceAddr ()))
228+ return
229+ }
230+ if len (raw [1 ]) <= 0 || len (raw [1 ]) > 5 {
231+ fail (resp , fmt .Sprintf ("get_source_addr: could not find port number '%s' from %s" , raw [1 ], req .GetSourceAddr ()))
232+ return
233+ }
234+ return true , 0
235+ }
236+
217237func fail (resp api.Response , msg string ) {
218238 resp .SetStatusCode (500 )
219239 resp .Headers ().Set ("x-httpwasm-tck-failed" , msg )
0 commit comments