标签: http-headers

向 WordPress 添加 http 标头

我正在尝试按需构建自定义 zip 文件,并发现一些代码似乎工作正常 http://www.9lessons.info/2012/06/creating-zip-file-with-php.html

我已将代码插入到我的 WordPress 模板中,唯一的事情是header()

必须在加载模板之前发送

我怎样才能用 WordPress 做到这一点?

这是带有标题的代码

$zip = new ZipArchive();            // Load zip library 
$zip_name = time().".zip";          // Zip name
if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){       // Opening zip file to load files
    $error .=  "* Sorry ZIP creation failed at this time<br/>";
}
foreach($post['files'] as $file){               
    $zip->addFile($file_folder.$file);          // Adding files into zip
}
$zip->close();
if(file_exists($zip_name)){
    // push to download the zip
    header('Content-type: application/zip');
    header('Content-Disposition: attachment; filename="'.$zip_name.'"');
    readfile($zip_name);
    // remove zip file is exists in temp path …
Run Code Online (Sandbox Code Playgroud)

wordpress http-headers

6
推荐指数
2
解决办法
1万
查看次数

在 app.yaml 中添加 HSTS 标头(Google App Engine)

我的 中有以下处理程序部分app.yaml:

handlers:
  - url: /(robots\.txt|sitemap\.xml)
    static_files: \1
    upload: (robots\.txt|sitemap\.xml)
    secure: always
    http_headers:
      Strict-Transport-Security: 'max-age=63072000; includeSubDomains; preload'
  - url: /.*
    script: main.app
    secure: always
    http_headers:
      Strict-Transport-Security: 'max-age=63072000; includeSubDomains; preload'
Run Code Online (Sandbox Code Playgroud)

由另一个子模块 ( static.yaml) 服务的另一个子域具有以下内容:

handlers:
  - url: /
    static_dir: files
    secure: always
    http_headers:
      Access-Control-Allow-Origin: '*'
      Strict-Transport-Security: 'max-age=63072000; preload'
Run Code Online (Sandbox Code Playgroud)

我能够static.yaml在没有任何问题的情况下部署应用程序引擎:

$ appcfg.py update static.yaml
12:48 PM Host: appengine.google.com
12:48 PM Application: XXXXXX; module: static; version: 1
12:48 PM
Starting update of app: XXXXXXXX, module: static, version: 1 …
Run Code Online (Sandbox Code Playgroud)

https google-app-engine http-headers app.yaml hsts

6
推荐指数
2
解决办法
5788
查看次数

Chrome 是否支持 HTTP Vary 标头

Chrome 的缓存支持 HTTP Vary 标头吗?对于特定的 url 请求,服务器响应两个不同的 html 文件,具体取决于它是否是 ajax 请求。所以我将 Vary 标头添加到 X-Requested-With 中。我本以为 Chrome 会记录两个缓存条目,但事实似乎并非如此。我总是收到我发出的第一个请求的缓存命中。这是正常行为吗?

谢谢。

google-chrome xmlhttprequest browser-cache vary http-headers

6
推荐指数
1
解决办法
895
查看次数

为什么204没有被OkHttp缓存?

查看中的代码,CacheInterceptor我发现带有代码 204 的响应没有被缓存。但我相信 204 是可缓存的,如此处所讨论的

我们使用204GET 的响应并不表示空响应,并且最近才注意到这些响应没有被缓存。

http cache-control http-headers okhttp

6
推荐指数
1
解决办法
689
查看次数

如何在 serverless.yml 中设置响应头?

我有无服务器 API,它与无服务器框架版本 1.25 一起使用

\n\n

出于安全原因,我想添加响应标头。请帮助我如何通过 serverless.yml 文件设置以下标头。出于安全原因是否有必要添加此标头?

\n\n

\xe2\x80\xa2 内容安全策略:包括 default-src 'self'

\n\n

\xe2\x80\xa2 严格传输安全 max-age=31536000; 包括子域;预载

\n\n

\xe2\x80\xa2 X-内容类型选项:nosniff

\n\n

\xe2\x80\xa2 X-XSS 保护:1

\n\n

\xe2\x80\xa2 缓存控制:max-age=0;过期=-1 或过期:1990 年 1 月 1 日星期五 00:00:00 GMT;无缓存,必须重新验证

\n\n

下面是我的无服务器应用程序 serverless.yaml

\n\n
service: myService\nprovider:\n  name: aws\n  runtime: nodejs6.10\n  stage: dev\n  region: eu-west-1\n  environment:\n    REGION: ${self:provider.region}\n    PROJECT_NAME: ${self:custom.projectName}\n    SERVERLESS_STAGE: ${self:provider.stage}\n    SERVERLESS_SERVICE: ${self:service}\n    IP_ADDRESS: http://example.com\nfunctions:\n   getMyFunction:\n     handler: handler.getMyFunction\n     timeout: 30\n     events:\n      - http:\n          method: get\n          path: api/getMyFunction/v1\n          integration: lambda\n          cors: true\n          authorizer:\n            name: authorizerFunc\n …
Run Code Online (Sandbox Code Playgroud)

javascript httpresponse amazon-web-services http-headers serverless-framework

6
推荐指数
1
解决办法
1万
查看次数

将 noindex 标头添加到 php 重定向文件

我有一个简单的 php 重定向脚本 (link.php),用于跟踪我们的联属链接。(例如: http: //www.example.net/link.php?id =1 会将您带到http://www.product1url.com)

我注意到 Google 正在索引http://www.example.net/link.php?id=1。我在 Robots.txt 中将 link.php 设置为 noindex,但这并没有停止索引。所以我想为每个 URL 本身添加一个“noindex”、“nofollow”标头。

这是我的脚本:

<?php

    $path = array(

    '1' => 'http://www.producturl1.com',
    '2' => 'http://www.producturl2.com',
    );

    if (array_key_exists($_GET['id'], $path))
     header('Location: ' . $path[$_GET['id']]);

 ?>
Run Code Online (Sandbox Code Playgroud)

如何修改它以包括:“X-Robots-Tag:noindex,nofollow”?这可能吗?

php redirect http-headers x-robots-tag

6
推荐指数
1
解决办法
8412
查看次数

如何使用express/node.js配置CSP标头?

我尝试让标签在express/node.js环境中工作,但不知何故它们总是被内容安全策略阻止。

\n\n

我已经尝试使用多个节点模块,例如express-csp-header或csp-header,但它们都没有成功。所以我又回到了“正常”的声明。

\n\n

这是我的 server.ts 脚本的顶部:

\n\n
app.use((req: any, res: any, next: any) => {\n    res.set({\n        "Access-Control-Allow-Origin": "*",\n        "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept",\n        "Access-Control-Allow-Methods": "GET, POST, PATCH, DELETE, OPTIONS",\n        "Content-Security-Policy": "default-src *",\n        "X-Content-Security-Policy": "default-src *",\n        "X-WebKit-CSP": "default-src *"\n    })\n    next();\n});\n
Run Code Online (Sandbox Code Playgroud)\n\n

它由 webpack 编译,node 运行在 localhost 上,端口为 3000。

\n\n

它不适用于仅“default-src *”或类似的。我什至尝试单独声明每种内容类型,例如

\n\n
"default-src * \'self\' \'unsafe-inline\' \'unsafe-eval\'; script-src * \'self\' \'unsafe-inline\' \'unsafe-eval\' localhost:*/*"\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是 html 页面的 body 标记之后的脚本部分:\n(将其放在 head 部分也没有改变任何内容)

\n\n
<script src="scripts/loginFunctions.js"></script>\n
Run Code Online (Sandbox Code Playgroud)\n\n

也许有一些重要的事情:\nHTML 输出由 squirrelly(express 的模板引擎)提供 …

javascript http-headers node.js express content-security-policy

6
推荐指数
1
解决办法
9146
查看次数

如何在浏览器控制台中查看 CORS 飞行前 OPTIONS 请求?

我正在寻找一种在发出 CORS 请求时查看 CORS 飞行前选项请求的方法。我想查看服务器的响应标头以帮助我调试遇到的 CORS 问题,但我无法在 Chrome 或 Firefox 的“网络”选项卡或控制台中找到执行此操作的方法。

我还安装了HTTP Header Live插件,但没有帮助。

我用来jQuery.get(url);触发我的 CORS 请求,其中url是不同域的 URL。

firefox google-chrome http-headers cors

6
推荐指数
1
解决办法
6209
查看次数

当我使用 HttpInterceptor 添加标头时,它们会添加到lazyUpdate,而不是标头数组

我已经通过 Angular 中的 HttpInterceptor 添加了授权标头,但输出似乎不正确。根据添加标头后的 JSON 输出,这感觉太笨拙而无法正确。我是否错误地添加了标头,或者我访问它们是否错误?:

headers["lazyUpdate"].forEach(x=>{x.name=='Authorization'}).value
Run Code Online (Sandbox Code Playgroud)

目标是回归Bearer mystring

拦截器调用:

{"url":" https://myurl ","body:{}, "reportProgress":false, "withCredentials":false, "responseType":"json", "method":"POST", "headers" :{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"params":{"updates":null,"cloneFrom":null,"encoder":{},"map" :null},"urlWithParams":"myurl"}

token.interceptor.ts:13拦截器添加token:

{"url":"myurl", "body":{}, "reportProgress":false, "withCredentials":false, "responseType":"json", "method":"POST", "headers":{" NormalizedNames":{},"lazyUpdate":[ {"name":"Authorization","value":"Bearer mystring","op":"s"} ], "headers":{},"lazyInit": {"normalizedNames":{},"lazyUpdate":null,"headers":{}}},"params":{"updates":null,"cloneFrom":null,"encoder":{},"map" :{}},"urlWithParams":"myurl"}

我的 TokenInterceptor 类:

@Injectable()
export class TokenInterceptor implements HttpInterceptor {
  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {   
    console.log('interceptor called: '+JSON.stringify(request))

    let r = request.clone({
      headers: request.headers.set('Authorization', `Bearer ${localStorage.getItem("id_token")}`)
    });
    console.log('interceptor added token: '+JSON.stringify(r))
    return next.handle(r);
  }
}
Run Code Online (Sandbox Code Playgroud)

http-headers angular-http-interceptors angular

6
推荐指数
0
解决办法
1025
查看次数

.Net core X-Forwarded-Proto 标头未正确传递到 Nginx

抱歉编辑历史记录,但这个问题对我来说真的不清楚,很难找到确切的问题。

我有一个在Nginx后面运行的.Net-Core Web 应用程序,并且X-Forwarded-Proto总是通过而不是.httphttps

启动.cs

 public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
            });

            services.AddMvc();

        }

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            //first middlewear
            app.UseForwardedHeaders();
             //and the rest
         }
Run Code Online (Sandbox Code Playgroud)

Nginx 配置

server {
    listen        80;
    server_name   example.com;
    location / {
        proxy_pass         http://localhost:5001/;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
}
Run Code Online (Sandbox Code Playgroud)

Nginx.conf

http {
    include …
Run Code Online (Sandbox Code Playgroud)

nginx http-headers .net-core asp.net-core

6
推荐指数
1
解决办法
3362
查看次数