标签: http-headers

httpd 重复 Access-Control-Allow-Origin 并带有“始终设置标头”

我正在尝试在我的服务器上启用 CORS。它同时托管 Apache HTTPD 和 Apache Tomee。HTTPD 配置为:

SetEnvIf Origin "^https://(.+\.)?my-domain.com$" allowed_origin=$0
Header always set Access-Control-Allow-Origin %{allowed_origin}e env=allowed_origin
Header set Access-Control-Allow-Credentials "true"
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS, HEAD, PUT, DELETE, PATCH"
Header set Access-Control-Allow-Headers "accept,x-requested-method,origin,x-requested-with,x-request,cache-control,content-type"
Header set Access-Control-Max-Age "600"
Run Code Online (Sandbox Code Playgroud)

和我的 Tomee web XML:

<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
  <init-param>
    <param-name>cors.allowed.headers</param-name>
    <param-value>Origin,Accept,X-Requested-With,Content-Type,Access-Control-Request-Method,Access-Control-Request-Headers,Accept-Language,Keep-Alive</param-value>
  </init-param>
  <init-param>
    <param-name>cors.allowed.methods</param-name>
    <param-value>GET,POST,HEAD,OPTIONS,PUT,PATCH,DELETE</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)

我的问题是我Access-Control-Allow-Credentials在对预检选项请求的响应中获得了两次标题:

HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://my-origin.my-domain.com
Access-Control-Allow-Origin: https://my-origin.my-domain.com
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 600
Access-Control-Allow-Methods: GET, POST, OPTIONS, HEAD, PUT, …
Run Code Online (Sandbox Code Playgroud)

apache http-headers cors apache-tomee

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

使用 libcurl 更改内容类型

我有这个代码:

#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();

    if(curl)
    {
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
        curl_easy_setopt(curl, CURLOPT_URL, "localhost/rest-v1/devices/did1/tasks");
        curl_easy_setopt(curl,CURLOPT_PORT,22080);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"hello\" : \"darkness\"}");

        res = curl_easy_perform(curl);

    }

    curl_easy_cleanup(curl);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我在控制台上得到这个打印:

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 22080 (#0)
> POST /rest-v1/devices/did1/tasks HTTP/1.1
Host: localhost:22080
Accept: */*
Content-Length: 16
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 16 out of 16 bytes
< HTTP/1.1 …
Run Code Online (Sandbox Code Playgroud)

c post http libcurl http-headers

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

在 Node 中仅获取 GET 请求的标头

我需要获得Content-LengthContent-Type的头文件与节点。

不幸的是,我正在处理的服务器不允许HEAD请求,而且文件太大而无法发出整个GET请求。

我正在寻找类似这个python代码的东西:

import requests

r = requests.get(url, stream=True)
content_length = r.headers['Content-Length']
content_type = r.headers['Content-Type']
Run Code Online (Sandbox Code Playgroud)

stream=True参数表示文件不会被完全下载。

get http http-headers node.js

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

AWS Elastic Load Balancer 不将 HTTP 标头转发到 EC2 实例

我目前正在 Amazon Elastic Beanstalk 上运行 Python Flask 应用程序。当我测试应用程序时,它在本地一切正常(我使用 Postman 发送 GET & POST 请求)。但是,在 AWS 上,它不起作用,因为到达我的 EC2 实例(在负载均衡器后面)的请求不包含Authorization标头。负载平衡器似乎剥离了标头。我在这里做错了吗?

这是我在本地和 Elastic Beanstalk 上打印标题时得到的比较。

本地

[2017-07-04 13:18:14,650] [INFO] [common.decorators] Headers = Host: localhost:5000 Connection: keep-alive Content-Length: 151 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Cache-Control: no-cache Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop Content-Type: application/json Authorization: Bearer ad9fd4d9-6ce6-497b-855a-dcebebdad65b Postman-Token: xxxxx Accept: */* Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.8

弹性豆茎:

[2017-07-04 17:27:03,813] [DEBUG] [common.decorators] Headers = Accept-Language: en-US,en;q=0.8 Accept: …

amazon-ec2 amazon-web-services http-headers amazon-elastic-beanstalk elastic-load-balancer

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

Content-Security-Policy HTTP 标头对 script-src 不起作用

我对我的 CSP 标头遵循Google 的严格 CSP 政策,并且我正在正确添加随机数,但是我的脚本在浏览器中不断收到此错误:

拒绝加载脚本 ' http://localhost:8080/client/dist/inline.6e0c61259742e86be1dd.bundle.js ' 因为它违反了以下内容安全策略指令:“script-src nonce-XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFxhxKQFDaFpLSEFWJFunc' -eval' '严格动态' https: http:"。存在“strict-dynamic”,因此禁用了基于主机的白名单。

如您所见,随机数与脚本中的随机数匹配:

<script type="text/javascript" src="/client/dist/inline.6e0c61259742e86be1dd.bundle.js" nonce="XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFpLSjFbcXoEFfRsWxP"></script>
Run Code Online (Sandbox Code Playgroud)

这是我用于script-src. "%s" 表示随机生成的随机数,它将在响应设置标头之前进行插值:

script-src nonce-%s 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:;
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么?

javascript browser security http http-headers

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

Angular 5 - 如何重定向到具有特定标题的外部 url?

这就是我试图用 Angular 实现的目标:

this.headers = ...;

this.http.get(`${urlApi}`).subscribe(data => {
    // go to url with specific headers
}, err => {
    console.log(err);
});
Run Code Online (Sandbox Code Playgroud)

当我从我的服务器得到一个 get 请求的响应时,我想重定向到一个带有特定标头的外部 url,以便能够在两个应用程序之间传递一些信息。

必须有办法做到这一点。我知道不可能使用window.location.href.

javascript http-headers typescript angular

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

从响应头中删除请求上下文

不知何故在我的请求响应标头“Request-Context”即将到来,我试图在 web.config 和 Response.Headers.Remove("Request-Context") 中删除它;在 global.asax 中,但该标题没有被删除。

在那个标头的值中,我得到了一些 Appid,我不确定它来自哪里。

这是我的请求的响应标头。

Cache-Control:no-cache, no-store
Content-Encoding:gzip
Content-Length:140
Content-Type:application/json; charset=utf-8
日期:2018 年 2 月 20 日星期二 09:48:28 GMT
Pragma:no-cache
Request-Context:appId=cid-v1:b650ed48-297a-4ea2-af46-0a5a5d26a82b
Vary:Accept-Encoding

任何帮助表示赞赏。提前致谢。

http-headers azure-application-insights azure-app-service-plans

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

HTTP 标头“Content-type: multipart/mixed”导致“400 Bad request”

我正在尝试使用 php 的 fsockopen 将文件上传到远程服务器。如果我的请求看起来像:

$httpContent = [
        "POST /index.php HTTP/1.1", 
        "Host: The IP address of my remote server", 
        "Connection: Close", 
        "User-Agent: My client"
];
Run Code Online (Sandbox Code Playgroud)

服务器响应200 OK. 但是,如果我添加

"Content-Type: multipart/mixed; boundary=".md5('myBoundary'), 
"--".md5('myBoundary'), 
"Content-Type: text/plain", 
"value", 
"--".md5('myBoundary')."--"
Run Code Online (Sandbox Code Playgroud)

服务器返回“400 Bad Request”。对我来说一切都很好,但不知何故它不起作用。我究竟做错了什么?

任何帮助是极大的赞赏!

编辑(@Rei 建议发布请求的转储):

这就是客户终端的回声

POST /index.php HTTP/1.1
Host: The IP address of my remote server
Connection: Close
User-Agent: My client
Content-Type: multipart/mixed; boundary=be0850c82dd4983ddc49a51a797dce49
--be0850c82dd4983ddc49a51a797dce49
Content-Type: text/plain
value
--be0850c82dd4983ddc49a51a797dce49--
Run Code Online (Sandbox Code Playgroud)

这就是服务器得到的(用 tcpdump 捕获的):

POST /index.php HTTP/1.1
Host: The IP address of …
Run Code Online (Sandbox Code Playgroud)

php http fsockopen http-headers

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

HttpHeaders getFirst() 不区分大小写

我正在使用 Spring 的 RestTemplate 获取 HTTP 标头。

HTTP 标头不区分大小写,但HttpHeaders文档似乎不承认这一点。

快速测试表明事情按预期工作......

HttpHeaders headers = restTemplate.headForHeaders(url);
Long a = Long.parseLong(headers.getFirst("Content-Length"));
Long b = Long.parseLong(headers.getFirst("content-length"));
assert( a.equals(b) ); // passes
Run Code Online (Sandbox Code Playgroud)

我能确定这个测试会在所有 Spring 配置下通过吗?

java spring http-headers resttemplate

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

webRequest listener doesn't see headers like 'cookie', 'referer', 'origin'

We wrote a Chrome-extension that, using the onBeforeSendHeaders event, adds a cookie to each web request:

chrome.webRequest.onBeforeSendHeaders.addListener(addCookie, {
    urls: ["<all_urls>"]
}, ["blocking", "requestHeaders"]);

function addCookie(details) {
    if (details.url.match(/ourWebsite/)) {
        details.requestHeaders.forEach(function (requestHeader) {
            if (requestHeader.name.toLowerCase() === "cookie") {
                //Code that adds a cookie with a value
            }
        });
        return {requestHeaders: details.requestHeaders};
    }
}
Run Code Online (Sandbox Code Playgroud)

它适用于每个人的 Chrome,但我自己的。在调试扩展时,我注意到details.requestHeaders数组没有cookie标头(这总是假的:)requestHeader.name.toLowerCase() === "cookie"

我的第一个想法是另一个扩展程序搞砸了我们的,所以我尝试隐身(不允许其他扩展程序),但它没有用。

在扩展的清单中,我们在permissions.

有任何想法吗?提前致谢!

javascript cookies http-headers google-chrome-extension

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