使用frisby 进行post的表单信息的提交,以及nginx缓存的命中

相关名称

post form ,$request_uri  nginx-cache

frisby测试,在客户端,进行post方式提交表单数据,客户端的nginx缓存信息无效
客户端也有nginx服务

使用frisby 进行post的表单信息的提交:
frisby的第一种尝试
//userMac     是     String     用户终端Mac
//sn     否     String     wifi设备SN
//adTypeId     是     Integer     广告类别Id '1':'展示类广告' '2':'视频贴片类广告'
//adPositionId     是     Integer     广告位id '1': '首页插屏' '2': '首页banner' '3': '首页底部浮层' '4': '频道页banner' '5': '自弹页全屏' '6': '自弹页半屏' '7': '外网劫持' '8': '首页红包浮层' '9': '自弹页红包浮层'
//channelId     否     Integer     频道Id '1': '电影' '2': '综艺' '3': '在线游戏' '4': '游戏下载'
function getADCachePush(sn, adTypeId, adPositionId, channelId) {
    let form = frisby.formData();
    form.append("sn", sn)
    form.append("adTypeId", adTypeId)
    form.append("adPositionId", adPositionId)
    form.append("channelId", channelId)
    //console.log("user-agent", uastr)
        // adCacheServer : http://....
    console.log("form", form)
    return new Promise(resolve => {
        return frisby.post(adCacheServer, {
                body: form
            })
            .expect("status", 200)
            .then(res => {
                //console.log(res)
                // console.log(res.headers)
                //console.log("adPushResult", res.json);
                resolve(res);
            })
    })
}


多次提交时,期望的是res.headers的 'nginx-cache': [ 'HIT' ]
结果却是'nginx-cache': [ 'MISS' ]


多次调查,发现,使用上面的方式,form信息,会被frisby字段添加了 下面的信息125081902639415250405831,而且,这一串数字每次请求都不相同。详细信息如下所示:
form data FormData {
      _overheadLength: 427,
      _valueLength: 2,
      _valuesToMeasure: [],
      writable: false,
      readable: true,
      dataSize: 0,
      maxDataSize: 2097152,
      pauseStreams: true,
      _released: false,
      _streams:
       [ '----------------------------125081902639415250405831\r\nContent-Disposition: form-data; name="sn"\r\n\r\n',
         '',
         [Function: bound ],
         '----------------------------125081902639415250405831\r\nContent-Disposition: form-data; name="adTypeId"\r\n\r\n',
         '1',
         [Function: bound ],
         '----------------------------125081902639415250405831\r\nContent-Disposition: form-data; name="adPositionId"\r\n\r\n',
         '1',
         [Function: bound ],
         '----------------------------125081902639415250405831\r\nContent-Disposition: form-data; name="channelId"\r\n\r\n',
         '',
         [Function: bound ] ],
      _currentStream: null,
      _boundary: '--------------------------125081902639415250405831' }




重新修改表单信息的提交方式,问题解决。
新代码如下:
//sn     否     String     wifi设备SN
//adTypeId     是     Integer     广告类别Id '1':'展示类广告' '2':'视频贴片类广告'
//adPositionId     是     Integer     广告位id '1': '首页插屏' '2': '首页banner' '3': '首页底部浮层' '4': '频道页banner' '5': '自弹页全屏' '6': '自弹页半屏' '7': '外网劫持' '8': '首页红包浮层' '9': '自弹页红包浮层'
//channelId     否     Integer     频道Id '1': '电影' '2': '综艺' '3': '在线游戏' '4': '游戏下载'
function getADCachePush(sn, adTypeId, adPositionId, channelId) {
    return new Promise(resolve => {
        return frisby.post(adCacheServer, {
                body: `sn=${sn}&adTypeId=${adTypeId}&adPositionId=${adPositionId}&channelId=${channelId}`
            })
            .expect("status", 200)
            .then(res => {
                //console.log(res)
                console.log("res.headers", res.headers)
                //console.log("adPushResult", res.json);
                resolve(res);
            })
    })
}


// 测试示例:
fit("simple test",function(done){
    getADCachePush("", 1, 1, "").then((res) => {
        console.log("getADCachePush (1)", res.json);
        setTimeout(() => {
            getADCachePush("", 1, 1, "").then((res) => {
                console.log("getADCachePush (2)", res.json);
                done();
            })
        }, 1000);
    })

})


命中结果:

onsole.log Spec\cpsPlanSpec.js:1922
    res.headers Headers {
      _headers:
       { server: [ 'nginx/1.7.10' ],
         date: [ 'Wed, 14 Mar 2018 10:04:36 GMT' ],
         'content-type': [ 'application/json;charset=UTF-8' ],
         'transfer-encoding': [ 'chunked' ],
         connection: [ 'close' ],
         'access-control-allow-origin': [ '*' ],
         'access-control-allow-methods': [ '*' ],
         'access-control-max-age': [ '100' ],
         'access-control-allow-headers': [ 'Content-Type' ],
         'access-control-allow-credentials': [ 'false' ],
         pragma: [ 'no-cache' ],
         expires: [ 'Thu, 01 Jan 1970 00:00:00 GMT' ],
         'cache-control': [ 'no-cache, no-store' ],
         'nginx-cache': [ 'HIT' ] } }



附1, nginx中的配置:
server {
        location ~* /media-ad/ {
        default_type text/html;
        rewrite ^/media-ad/(.*)/(.*) /$1/api/advertise/cache break;
        proxy_pass https://139.219.99.153;
        proxy_cache media_cache;
        proxy_cache_valid 200 1h;
        proxy_cache_methods POST;
        proxy_cache_key "$request_uri|$request_body";
        proxy_ignore_client_abort on;
        proxy_cache_lock on;
        proxy_cache_lock_timeout 60s;
        add_header  Nginx-Cache "$upstream_cache_status";
    }

}    


附2,nginx中有几个关于uri的变量的区别

--【引用地址】https://www.cnblogs.com/JohnABC/p/6182826.html

--在nginx中有几个关于uri的变量,包括$uri、$request_uri、$document_uri,下面看一下他们的区别 :
--$request_uri: /stat.php?id=1585378&web_id=1585378
--$uri /stat.php
--$document_uri: /stat.php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值