如何覆盖nginx中的默认Content-Type?目前,当我请求01.dae文件时,有
Content-Type: application/octet-stream;
Run Code Online (Sandbox Code Playgroud)
我希望它成为现实
Content-Type: application/xml;
Run Code Online (Sandbox Code Playgroud)
我试过类似的东西
location ~* \.dae$ {
types { };
default_type application/xml;
}
Run Code Online (Sandbox Code Playgroud)
和
location ~* \.dae$ {
add_header Content-Type application/xml;
}
Run Code Online (Sandbox Code Playgroud)
但没有任何作用.
在映射User-Agent HTTP Header字符串 - >操作系统的任何地方都有一个好的,最新的列表吗?
我有以下代码Python:
from selenium.webdriver import Firefox
from contextlib import closing
with closing(Firefox()) as browser:
browser.get(url)
Run Code Online (Sandbox Code Playgroud)
我想打印用户代理HTTP标头,并可能更改它.可能吗?
我正在执行一些WPO任务,因此PageSpeed建议我利用浏览器缓存.我已经成功改进了我的Nginx服务器中的一些静态文件,但是仍然缺少存储在Amazon S3服务器中的图像文件.
我已经阅读了有关更新S3中每个文件的方法,以包含一些标头元标记(Expires和Cache-Control).我认为这不是一个好方法.我有成千上万的文件,所以这对我来说不可行.
我认为最方便的方法是配置我的Nginx 1.6.0服务器来代理S3文件.我已经读过这个,但我在服务器配置上并不熟练,所以我从这些网站得到了几个例子:https://gist.github.com/benjaminbarbe/1961db5ffbaad57eff12
我在我的nginx配置文件中的服务器块中添加了这个位置代码:
#inside server block
location /mybucket.s3.amazonaws.com/ {
proxy_http_version 1.1;
proxy_set_header Host mybucket.s3.amazonaws.com;
proxy_set_header Authorization '';
proxy_hide_header x-amz-id-2;
proxy_hide_header x-amz-request-id;
proxy_hide_header Set-Cookie;
proxy_ignore_headers "Set-Cookie";
proxy_buffering off;
proxy_intercept_errors on;
proxy_pass http://mybucket.s3.amazonaws.com;
}
Run Code Online (Sandbox Code Playgroud)
当然,这对我不起作用.我的请求中不包含标头.所以,首先我认为请求与位置不匹配.
Accept-Ranges:bytes
Content-Length:90810
Content-Type:image/jpeg
Date:Fri, 23 Jun 2017 04:53:56 GMT
ETag:"4fd0be549fbcaf9b47c18a15146cdf16"
Last-Modified:Tue, 09 Jun 2015 09:47:13 GMT
Server:AmazonS3
x-amz-id-2:cKsq1qRra74DqVsTewh3P3sgzVUoPR8aAT2NFCuwA+JjCdDZfk7/7x/C0WPjBa51GEb4C8LyAIc=
x-amz-request-id:94EADB4EDD3DE1C1
Run Code Online (Sandbox Code Playgroud) 我希望用户能够下载我服务器上的一些文件,但是当我尝试使用互联网上的任何一个这样的例子时,似乎没有什么对我有用.我尝试过这样的代码:
<?php
$size = filesize("Image.png");
header('Content-Description: File Transfer');
header('Content-Type: image/png');
header('Content-Disposition: attachment; filename="Image.png"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $size);
readfile("Image.png");
Run Code Online (Sandbox Code Playgroud)
我甚至试图使用我能找到的最基本的例子,如下所示:
<?php
header('Content-type: image/png');
header('Content-Disposition: attachment; filename="Image.png"');
readfile('Image.png');
Run Code Online (Sandbox Code Playgroud)
当我测试了这个时,我已经删除了所有其他代码,并使用了一个空文件,仅使用此代码来删除外部源创建的任何错误.
当我在控制台中查看时,文件会以正确的标题发送,即
'Content-Disposition: attachment; filename="Image.png"'
Run Code Online (Sandbox Code Playgroud)
但是不显示保存对话框.
我也尝试使用inline而不是内容处理标题中的附件,但这也没有什么区别,我已经在Firefox 8.0.1 Chrome 15.0.874.121和Safari 5.1.1中测试过了.
我正在尝试csv从node.js服务器流式传输文件.服务器部分非常简单:
server.get('/orders' function(req, res) {
res.setHeader('content-type', 'text/csv');
res.setHeader('content-disposition', 'attachment; filename='orders.csv');
return orders.pipe(res); // assuming orders is a csv file readable stream (doesn't have to be a stream, can be a normal response)
}
Run Code Online (Sandbox Code Playgroud)
在我的角度控制器中,我试图做这样的事情
$scope.csv = function() {
$http({method: 'GET', url: '/orders'});
};
Run Code Online (Sandbox Code Playgroud)
ng-click在我的视图中点击按钮时调用此函数:
<button ng-click="csv()">.csv</button>
Run Code Online (Sandbox Code Playgroud)
我已经查看了有关从Angular中的服务器下载文件的其他答案,但没有找到任何对我有用的内容.有一个共同的方法来做到这一点?似乎应该很简单.
浏览器何时不向服务器请求文件?
换句话说,我有一个JavaScript文件正在服务.其HTTP响应报头具有一个ETag,Cache-Control: public和Expires: Tue, 19 Jan 2038 03:14:07 GMT.
304浏览器缓存已准备好后服务器返回a .
我的问题是,为什么浏览器甚至检查服务器并首先获得一个304?我不希望浏览器询问是否有新版本 - 它应该直接从浏览器缓存加载而不检查服务脚本的服务器的修改.
HTTP响应头的哪些组合实现了这一点?
我试图理解这一点,并搜索SO以寻找类似的问题,但我仍然没有100%理解它应该如何工作.
我对图像资源的请求得到了这个响应:
Response Headers
Server Apache-Coyote/1.1
Date Mon, 19 Oct 2009 09:04:04 GMT
Expires Mon, 19 Oct 2009 09:06:05 GMT
Cache-Control public, max-age=120
Etag image_a70703fb393a60b6da346c112715a0abd54a3236
Content-Disposition inline;filename="binary-216-420"
Content-Type image/jpg;charset=UTF-8
Content-Length 4719
Run Code Online (Sandbox Code Playgroud)
所需的行为是客户端应该缓存120秒,然后再次从服务器请求它.在120秒内,没有请求发送到服务器.
然后,在120秒后,发送请求并收到304响应:
Response Headers
Server Apache-Coyote/1.1
Date Mon, 19 Oct 2009 09:06:13 GMT
Request Headers
Host localhost:8080
User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
Accept image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language en-us,no;q=0.8,sq;q=0.7,en;q=0.5,sv;q=0.3,nn;q=0.2
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
Referer http://localhost:8080/cms/site/0/en/home
Cookie JSESSIONID=768ABBE1A3BFABE3B535900233330650; versionsCssDisplayState=block; iceInfo=iceOn:false,activePortletKey:,icePagePanelX:1722,icePagePanelY:3
If-None-Match …Run Code Online (Sandbox Code Playgroud) 是否可以在JavaScript中仅使用XMLHTTPRequest来执行HTTP头请求?
我的动机是节省带宽.
如果没有,是否有可能伪造它?
我正在使用Pattern/ Matcher来获取HTTP响应中的响应代码.groupCount返回1,但在尝试获取它时我得到一个例外!知道为什么吗?
这是代码:
//get response code
String firstHeader = reader.readLine();
Pattern responseCodePattern = Pattern.compile("^HTTP/1\\.1 (\\d+) OK$");
System.out.println(firstHeader);
System.out.println(responseCodePattern.matcher(firstHeader).matches());
System.out.println(responseCodePattern.matcher(firstHeader).groupCount());
System.out.println(responseCodePattern.matcher(firstHeader).group(0));
System.out.println(responseCodePattern.matcher(firstHeader).group(1));
responseCode = Integer.parseInt(responseCodePattern.matcher(firstHeader).group(1));
Run Code Online (Sandbox Code Playgroud)
这是输出:
HTTP/1.1 200 OK
true
1
Exception in thread "Thread-0" java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Unknown Source)
at cs236369.proxy.Response.<init>(Response.java:27)
at cs236369.proxy.ProxyServer.start(ProxyServer.java:71)
at tests.Hw3Tests$1.run(Hw3Tests.java:29)
at java.lang.Thread.run(Unknown Source)
Run Code Online (Sandbox Code Playgroud) http-headers ×10
etag ×2
http ×2
javascript ×2
nginx ×2
user-agent ×2
ajax ×1
amazon-s3 ×1
angularjs ×1
caching ×1
content-type ×1
html ×1
java ×1
node.js ×1
php ×1
proxy ×1
python ×1
regex ×1
selenium ×1