标签: http-headers

Pandas read_csv from URL and include request header

As of Pandas 0.19.2, the function read_csv() can be passed a URL. See, for example, from this answer:

import pandas as pd

url="https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv"
c=pd.read_csv(url)
Run Code Online (Sandbox Code Playgroud)

The URL I'd like to use is: https://moz.com/top500/domains/csv

With the above code, this URL returns an error:

urllib2.HTTPError: HTTP Error 403: Forbidden
Run Code Online (Sandbox Code Playgroud)

based on this post, I can get a valid response by passing a request header:

import urllib2,cookielib

site= "https://moz.com/top500/domains/csv"
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11', …
Run Code Online (Sandbox Code Playgroud)

python http-headers pandas python-requests

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

返回响应头 OnAuthenticationFailed

如果用户发送的令牌已过期,我将尝试返回更改的标头,以便我可以在它过期时重新发送我的刷新令牌。

我将 .NET Core 2.2 与“In-Process”托管一起使用,这很重要。

这是我ConfigureServices从我的Startup.cs.

services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = "bearer";
    options.DefaultChallengeScheme = "bearer";
}).AddJwtBearer("bearer", options =>
{
    options.TokenValidationParameters = new TokenValidationParameters
    {
        ValidateAudience = false,
        ValidateIssuer = false,
        ValidateIssuerSigningKey = true,
        IssuerSigningKey = new SymmetricSecurityKey(System.Text.Encoding.UTF8.GetBytes(Configuration["serverSigningPassword"])),
        ValidateLifetime = true,
        ClockSkew = System.TimeSpan.Zero //the default for this setting is 5 minutes
    };
    options.Events = new Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerEvents
    {
        OnAuthenticationFailed = context =>
        {
            if (context.Exception.GetType() == typeof(SecurityTokenExpiredException))
            {
                context.Response.Headers.Add("Token-Expired", "true");
            }
            return System.Threading.Tasks.Task.CompletedTask;
        }
    };
}); …
Run Code Online (Sandbox Code Playgroud)

javascript c# api http-headers asp.net-core

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

在 Wildfly 10 中配置 HTTP 标头

有没有办法配置 Wildfly(10 个或更多)发送到客户端的 Http 标头仅配置以下内容:

HTTPS 严格传输安全 (HSTS) X-XSS-Protection X-Frame-Options Strict-Transport-Security Content-Security-Policy X-Content-Type-Options

我有一个配置文件(standalone.xml),其中包含所有配置。我需要在这里添加标题的配置。

security http-headers servlet-filters undertow wildfly-10

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

如何将授权承载头添加到 webview android?

我必须在标题处发送承载。我看到我必须添加带有值的 hashMap:

val headerMap = HashMap<String, String>()
headerMap["Authorization: Bearer "] = context!!.getSharedPreferences("app_data", 0).getString("access_token", "")!!
Run Code Online (Sandbox Code Playgroud)

然后使用 url 发送数据:

webView.loadUrl(link, headerMap)
Run Code Online (Sandbox Code Playgroud)

但结果我发现我发送了错误的令牌格式:

authorization=bearer :token
Run Code Online (Sandbox Code Playgroud)

我如何修复它,因为使用该令牌我无法从页面获取数据?

android http-headers android-webview kotlin

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

在 cloudflare worker header.set('Set-Cookie' function) 的“Set-Cookie”标头中设置多个 cookie

我正在尝试使用 cloudfare 工作人员在将响应发送到客户端之前将 2 个 cookie 键/值对添加到响应中。

不幸的是,cloudflare 工作人员的所有文档都说使用 response.headers.set('Set-Cookie',xxx) 函数来设置 cookie 值:

let response = await fetch(request);
response = new Response(response.body, response);

response.headers.set('Set-Cookie', "val1=x; Expires=Wed, 21 Oct 2020 07:28:00 GMT; Path='/';");

return response;
Run Code Online (Sandbox Code Playgroud)

这仅允许您设置一个 cookie 标头,如果调用两次只会覆盖现有的标头。

我试过两次调用该函数,只有最后一个值进来:

response.headers.set('Set-Cookie', "val1=1; Expires=Wed, 21 Oct 2020 07:28:00 GMT; Path='/';");
response.headers.set('Set-Cookie', "val2=2; Expires=Wed, 21 Oct 2020 07:28:00 GMT; Path='/';");
Run Code Online (Sandbox Code Playgroud)

我尝试在一个标题中传递 2 个 cookie,用逗号分隔,但只有一个进来:

response.headers.set('Set-Cookie', "val1=1; Expires=Wed, 21 Oct 2020 07:28:00 GMT; Path='/';, val2=2; Expires=Wed, 21 Oct 2020 07:28:00 GMT; Path='/';");
Run Code Online (Sandbox Code Playgroud)

我尝试传递 2 个 …

cookies http-headers cloudflare-workers

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

基于自定义头的 Spring Security antMatcher 规则

在 Spring 框架中,我目前正在尝试使用自定义标头而不是 url 来区分某些端点。目前,我似乎看不到如何允许具有自定义标头的特定 URL,但在 Spring Security 中拒绝另一个 URL。我的安全配置目前有一个 antMatcher,如下所示:

.antMatchers( HttpMethod.POST, "/api/website-user" ).permitAll()
Run Code Online (Sandbox Code Playgroud)

但是,我还有一些其他“POST”方法也受到保护 - 对于这个特定的端点,我只希望通过发送的标头来识别和排除它。

你如何告诉 Spring 安全这个 URL 应该未经身份验证通过

 @PostMapping( headers = "X-Operation-Name=forgot-password" )
   public WebsiteUser forgotPassword( @Valid PasswordResetRequestModel passwordReset )
Run Code Online (Sandbox Code Playgroud)

但是例如这个没有(并且依赖于经过身份验证的用户)?

@PostMapping( headers = "X-Operation-Name=resend-verification" )
   public WebsiteUser resendVerification( Principal principal )
Run Code Online (Sandbox Code Playgroud)

java spring spring-security http-headers spring-boot

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

来自请求 Python 库的 HTTP 请求中缺少主机标头

Python 库生成的 HTTP 请求消息中的HTTP/1.1 强制 Host 头字段requests哪里?

import requests

response = requests.get("https://www.google.com/")
print(response.request.headers)
Run Code Online (Sandbox Code Playgroud)

输出这个:

{'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'}

python http http-headers python-requests

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

如何在 Spring 中修改响应的 ReadOnlyHttpHeaders?

RestTemplate.exchange 正在返回一个带有 ReadOnlyHttpHeaders 的 ResponseEntity。我想添加/修改这些标题,但由于它是只读的,我该怎么做?

java spring http-headers

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

为什么 Firefox 会忽略缓存标头并在刷新时重新验证?

我有一些不可变的图像资源,可以永久缓存。Chrome 似乎尊重我的响应标头,并且不会重新验证资源:

Chrome 请求

以下是 Chrome 中这些资源之一的示例。正如你所看到的,我包括cache-control: public, max-ageexpiresetaglast-modified和资源从“内存缓存”服务:

Chrome 请求


但是,Firefox 不尊重这些标头并在每次加载时重新验证资源!每次页面加载时,我的服务器都会收到对每个个人资料图片的请求,并返回 304:

Firefox 请求

这是导致 304 的此类请求的示例:

火狐请求

我不明白为什么 Firefox 会忽略缓存标头并继续访问 304 的服务器。我已经尝试了各种与缓存相关的标头并阅读了关于什么是"cacheable"的标准。我确保在 devtools 中启用了缓存。我也尝试过关闭 devtools,但我一直在服务器日志中看到 304。

我发现这只会在页面刷新时发生。但是,普通刷新,不是 shift- 或 shift-command-,而只是普通刷新。这不是我期望的行为。

browser firefox caching http http-headers

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

使用 htaccess 设置 Cookie

我在Apache服务器上使用WordPress,并希望在有人第一次登陆我的网站时使用我的.htaccess设置 cookie。

如果可能,我会将两个Cookie设置为:

  1. 存储完整的 URL
  2. 将值存储在 URL 的参数中(例如teamname

通常在 PHP 中,我只有:

function set_user_cookie() {
    $url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    if (!isset($_COOKIE['LandingPageURL'])) {
        setcookie('LandingPageURL', $url, time()+2678400, "/");
    }
}
add_action( 'init', 'set_user_cookie');
Run Code Online (Sandbox Code Playgroud)

然而,我们一直注意到缓存问题,所以我想知道是否可以在我的.htaccess 中实现这一点。

示例网址:www.example.com/?teamname=Chicago+Bulls

php apache cookies .htaccess http-headers

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