标签: http-headers

在 PHP 中获取当前的 Content-Type 标头

我正在运行一个 PHP 脚本来将所有对我的站点的请求记录在 MySQL 数据库中。例如,我网站上的一些脚本还修改Content-Type用于输出图像的标题。header("Content-Type: image/png");我也在尝试记录这个内容类型。如何获取包含 Content-Type 的字符串变量?

php logging http-headers

4
推荐指数
1
解决办法
2157
查看次数

HTTPS Host: 标头中显式默认端口的定义行为?

在 HTTPS 中,如果主机标头中提供/未提供默认端口,服务器的行为是否应该有所不同?也就是说,在 HTTPS 中,将这两个标头视为请求的一部分:

Host: www.example.com

Host: www.example.com:443
Run Code Online (Sandbox Code Playgroud)

据我所知,HTTP 规范规定必须包含端口,除非它是默认端口。但是,据我所知,它没有提到如果显式包含默认端口该怎么办(因为不需要)。我似乎找不到任何有关 HTTPS 的信息,这正是我在这种情况下感到好奇的地方。

与此问题类似,它处理 HTTP 并询问是否需要端口。

对于上下文,我正在使用Mechanize Python 模块,并且在通过登录服务处理一些 302 重定向时,最终发送包含默认端口(即 443)的 Host: 标头。但是,接收此标头的服务器似乎不喜欢它,并且只有在不包含端口时才能正常运行。我试图确定这是否是服务器中的错误,或者机械化中的错误,或者两者都不是。我认为是前者,但我只有能力改变机械化的工作方式。

https networking http http-headers

4
推荐指数
1
解决办法
1388
查看次数

Golang 中的服务器头中间件

我正在尝试在每个响应上设置服务器标头。我正在尝试使用Gin 中间件来实现这一目标。但是,由于某种原因,这不会设置标头。到目前为止,我已经尝试对此进行调试,但我无法理解为什么这不起作用。也许我在这里遗漏了一些东西。

\n\n

这是代码

\n\n
package main\n\nimport "fmt"\nimport "github.com/gin-gonic/gin"\n\nconst SERVER_INFO = "Some-Play-Server"\n\ntype ServerHeader struct {\n    gin.ResponseWriter\n    ServerInfo string\n}\n\nfunc (w *ServerHeader) Write(data []byte) (int, error) {\n    if w.Header().Get("Server") == "" {\n        w.Header().Add("Server", w.ServerInfo)\n    }\n\n    return w.ResponseWriter.Write(data)\n}\n\nfunc InitServerHeader() gin.HandlerFunc {\n    return func(c *gin.Context) {\n        writer := &ServerHeader{c.Writer, SERVER_INFO}\n        c.Writer = writer\n        c.Next()\n    }\n}\n\nfunc main() {\n    mux := gin.Default()\n    mux.Use(InitServerHeader())\n    mux.GET("/", func(c *gin.Context) {\n        c.String(200, "OK")\n    })\n\n    fmt.Println("Server Listening on 0.0.0.0:8080")\n    mux.Run(":8080")\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

而且,这是测试输出

\n\n
\xe2\x9d\xaf curl -v http://localhost:8080/\n* About to …
Run Code Online (Sandbox Code Playgroud)

http go http-headers

4
推荐指数
1
解决办法
8472
查看次数

当用户点击 iframe 内的链接(覆盖 Chrome 中的新选项卡)时,“Referer”标头丢失

问题

这是浏览器的预期行为吗?

相关的 Chromium bug

https://code.google.com/p/chromium/issues/detail?id=492761

脚步

  1. 为 Chrome创建一个空扩展程序

  2. 将 newtab 覆盖放入manifest.json:"chrome_url_overrides": {"newtab": "newtab.html"}

  3. create newtab.html( chrome-extension://<extension_id>/newtab.html),创建一个 iframe 并向其中加载一些页面,例如https://<some_page>.com/

  4. 添加指向该页面的链接,例如https://example.org/

  5. 单击该链接并观察请求

预期结果

应存在“Referer”标头,例如:

GET / HTTP/1.1
Host: example.org
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.65 Safari/537.36
Referer: https://<some_page>.com/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,de;q=0.6,ru;q=0.4
Cookie: ...
Run Code Online (Sandbox Code Playgroud)

实际结果

没有“Referer”标头:

GET / HTTP/1.1
Host: example.org
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 …
Run Code Online (Sandbox Code Playgroud)

iframe http-referer http-headers google-chrome-extension

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

nginx proxy_pass 正在设置响应端口

我的 Nginx 配置类似于:

server {
    listen 80;
    listen 443;
    server_name api.mysite.dev;

    location / {

        proxy_set_header Host "api.mysite.dev";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass  $scheme://127.0.0.1:8001;
    }

}

server {
    listen 80;
    listen 443;
    server_name mysite.dev www.mysite.dev;

    # Forward all /api/ requests ti api.mysite.dev
    # sadly need to keep this around for backwards compatibility
    location /api/ {
        proxy_set_header Host "api.mysite.dev";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass $scheme://127.0.0.1:8001/;

    }
    # The proxy_pass here ends up putting the port (8002) in the response URL.
    location / {
        proxy_set_header …
Run Code Online (Sandbox Code Playgroud)

proxy reverse-proxy nginx http-headers

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

获取 cURL 响应标头以及响应正文

我正在使用 Imgur API 上传图像。他们在API 文档中详细说明,每个请求(当我通过他们的 API 上传图像时)也有响应标头,这将告诉我该帐户还剩多少信用额。

我需要返回 HTTP 响应标头X-RateLimit-ClientRemaining。这是我当前用来获取 cURL 正文的代码:

$filename = dirname(realpath(__FILE__))."/images/$value";
$client_id = "f*************c";
$handle = fopen($filename, "r");
$data = fread($handle, filesize($filename));
$pvars   = array('image' => base64_encode($data));
$timeout = 30;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
$out = curl_exec($curl);
curl_close ($curl);
$pms = json_decode($out,true);
$url=$pms['data']['link'];
if($url!=""){
    // add to success
    array_push($success, $url);
} …
Run Code Online (Sandbox Code Playgroud)

php api curl http-headers imgur

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

如何访问 Servant 中的 http 标头?

我有一个带有 REST API 的简单仆人应用程序:

type API = "items" :> Get '[JSON] [MyData]

app :: Application
app = serve api server

api :: Proxy API
api = Proxy

server :: Server API
server = getItems

getItems :: ExceptT ServantErr IO [MyData]
getItems = ......

startApp :: IO ()
startApp = run 1234 app
Run Code Online (Sandbox Code Playgroud)

如何根据条件访问 http 标头并返回特定响应(例如 http403)?

rest haskell http http-headers servant

4
推荐指数
1
解决办法
919
查看次数

HTML5 视频元素不请求结束范围

我有一个<video>and<audio>元素,它通过范围请求从我的服务器加载文件(mp4、mp3,无关紧要)。

然而,该元素似乎只从我的服务器请求结束范围,并从那里开始尝试直接从字节 0 流到末尾,导致播放器陷入“下载循环”,这使得浏览器暂停所有内容其他操作直至下载完成。

范围请求 1

范围请求2

有谁知道这个问题的解决方案?例如,我是否必须使我的流请求有一个实际的结束content length或accept-ranges?

这是来自 Chrome 的完整请求列表,在底部您可以看到对该 url 的请求view?watch=v__AAAAAA673pxX一直处于待处理状态,基本上直到element.

全范围请求历史记录

简而言之:在使用http-range请求时,html5 元素会陷入下载循环,并导致所有其他请求保持“待处理”状态。

更新

该问题已在服务器端得到解决。

虽然原始流函数实际上会输出每个字节,但我修改了代码以仅输出实际缓冲区的大小。这迫使系统elements对剩余数据发出新请求。

这里的一个重要注意事项是返回content-length, ,accept-ranges并且content-ranges与每个请求中的文件大小、开始和结束位置相匹配HTTP RANGE。

供将来参考:

function stream(){
    $i = $this->start;
    set_time_limit(0);
    while(!feof($this->stream) && $i <= $this->end) {
        $bytesToRead = $this->buffer;
        if(($i+$bytesToRead) > $this->end) {
            $bytesToRead = $this->end - $i + 1;
        }
        $data = fread($this->stream, $bytesToRead);
        echo $data;
        flush();
        $i += …
Run Code Online (Sandbox Code Playgroud)

html javascript php http-headers http-range

4
推荐指数
1
解决办法
6795
查看次数

NestJS 从 GridFS 返回一个文件

我正在尝试使用我的 Nest 控制器从 GridFS 返回一个文件。据我所知,nest 不尊重我content-type设置的自定义标头application/zip,因为我在返回时收到了文本内容类型(请参见屏幕截图)。

响应数据图像,错误的内容类型标头

我的巢控制器看起来像这样

  @Get(':owner/:name/v/:version/download')
  @Header('Content-Type', 'application/zip')
  async downloadByVersion(@Param('owner') owner: string, @Param('name') name: string, @Param('version') version: string, @Res() res): Promise<any> {
    let bundleData = await this.service.getSwimbundleByVersion(owner, name, version);
    let downloadFile = await this.service.downloadSwimbundle(bundleData['meta']['fileData']['_id']);   
    return res.pipe(downloadFile);
  }
Run Code Online (Sandbox Code Playgroud)

这是服务电话

downloadSwimbundle(fileId: string): Promise<GridFSBucketReadStream> {
      return this.repository.getFile(fileId)
    }
Run Code Online (Sandbox Code Playgroud)

这本质上是对此的传递。

  async getFile(fileId: string): Promise<GridFSBucketReadStream> {
    const db = await this.dbSource.db;
    const bucket = new GridFSBucket(db, { bucketName: this.collectionName });
    const downloadStream = bucket.openDownloadStream(new ObjectID(fileId));

    return new Promise<GridFSBucketReadStream>(resolve …
Run Code Online (Sandbox Code Playgroud)

zip get httpresponse http-headers nestjs

4
推荐指数
1
解决办法
4270
查看次数

作为客户端应用程序,我如何从 Amazon 负载均衡器 (ALB) 获取转发给我的“x-amzn-oidc-*”标头?

我计划设置 ALB (Amazon Load Balancer) 以进行身份​​验证。它会坐在我的客户端应用程序,并与和的access_token用户要求的智威汤逊页眉只转发认证请求前,x-amzn-oidc-accesstoken+x-amzn-oidc-data分别为[0]。

我的客户端应用程序需要捕获这些转发的标头并将它们存储在 localStorage 中,以便在以后的请求(例如 S3)中访问其他 AWS 资源。

如果我是接收 ALB 请求的客户端应用程序,我将如何拦截这些标头?他们是作为请求还是响应进来的?

[0] 参见图中的第 10 步:https : //www.exampleloadbalancer.com/auth_detail.html

reverse-proxy http amazon-web-services http-headers

4
推荐指数
1
解决办法
1426
查看次数