我正在重写 url 并用 siege 对其进行测试,但我遇到了一个问题。
有时,gwan 在处理程序连接中对主函数的 2 次调用使用相同的地址。为了在两次调用之间有所不同,我使用带有 rand() 的整数。
在下面的示例中,我们发现 2 个调用的相同地址非常接近......
init 1412811699 : buff 0x10d3760 -> GET /imagesproduitnew-100018-imagesgallery/BIG-1.jpg HTTP/1.1
init 687109171 : buff 0x10d3760 -> GET /imagesproduitnew-100018-imagesgallery/BIG-1.jpg HTTP/1.1
regex OK 1412811699 : buff 0x10d3760 -> GET /imagesproduitnew-100018-imagesgallery/BIG-1.jpg HTTP/1.1
extarctPart 1412811699 : buff 0x10d3760 -> GET /imagesproduitnew-100018-imagesgallery/BIG-1.jpg HTTP/1.1
regex OK 687109171 : buff 0x10d3760 -> GET /imagesproduitnew-100018-imagesgallery/BIG-1.jpg HTTP/1.1
rewriteJPG 1412811699 : buff 0x10d3760 -> GET /imagesproduitnew-100018-imagesgallery/BIG-1.jpg HTTP/1.1
xbufreplace 1412811699 : buff 0x10d3760 -> GET /imagesproduitnew/imagesgallery/BIG/100018.jpg HTTP/1.1
-- HERE buffer is changed by the previous step because both have the same address --
extarctPart 687109171 : buff 0x10d3760 -> GET /imagesproduitnew/imagesgallery/BIG/100018.jpg HTTP/1.1
为了解决这个问题,我使用来自其他服务器的 siege 以及不同 URL 的列表。
谢谢你的帮助
我需要重写 URL:/-100018-imagesgallery/BIG-1.jpg 必须发送到文件 /imagesproduitnew/imagesgallery/BIG/100018.jpg
我的代码:
int main(int argc, char *argv[])
{
const long state = (long)argv[0];
if(state == HDL_AFTER_READ)
{
int test = rand();
xbuf_t *read_xbuf = (xbuf_t*)get_env(argv, READ_XBUF);
printf ("init %i : buff %p -> %s\n", test, read_xbuf->ptr, read_xbuf->ptr);
//function to test if URL needs to be rewrite
if(regexRewriteJPG(read_xbuf->ptr) == 0){
printf ("regex OK %i : buff %p -> %s\n", test, read_xbuf->ptr, read_xbuf->ptr);
char *URL;
char *newURL;
//extractPart, extract the URL from buffer (/imagesproduitnew-100018-imagesgallery/BIG-1.jpg for exemple)
URL = extractPart(read_xbuf->ptr, str_regexJPG);
printf ("extarctPart %i : buff %p -> %s\n", test, read_xbuf->ptr, read_xbuf->ptr);
if(URL){
//rewriteJPG return the reel path of the file (/imagesproduitnew/imagesgallery/BIG/100018.jpg for exemple)
newURL = rewriteJPG(URL);
printf ("rewriteJPG %i : buff %p -> %s\n", test, read_xbuf->ptr, read_xbuf->ptr);
if(newURL){
xbuf_repl(read_xbuf, URL, newURL);
printf ("xbufreplace %i : buff %p -> %s\n", test, read_xbuf->ptr, read_xbuf->ptr);
free(newURL);
}
else{
printf("newURL is NULL\n");
}
free(URL);
}
else{
printf("URL is NULL\n");
}
}
printf ("END %i : buff %p -> %s\n", test, read_xbuf->ptr, read_xbuf->ptr);
}
return 255; // execute next connection
}