При попытке получить заголовки из ответа с использованием API-интерфейса выборки (обернутого клиентом Aurelia-fetch-client) объект заголовков пуст;
Вот мой метод привлечения клиентов
public GetCustomers(): Promise<CustomerList> {
let customerList = new CustomerList();
return this._http.fetch('/api/customers')
.then(response => {
let links = response.headers.get('Link');
customerList.pagination.pageCount = parseInt(response.headers.get('X-Pagination.pageCount'));
customerList.pagination.pageNumber = parseInt(response.headers.get('X-Pagination.pageNumber'));
customerList.pagination.pageSize = parseInt(response.headers.get('X-Pagination.pageSize'));
customerList.pagination.totalItems = parseInt(response.headers.get('X-Pagination.totalItems'));
console.log(response.headers);
return response.json() as any
}).then(data =>{
data.map(
item => {
let customer: Customer = new Customer(this);
Object.assign(customer, item);
customerList.customers.push(customer);
});
return customerList;
});
}
Конфигурация HTTP-загрузки
constructor(private eventAggregator: EventAggregator, url: string) {
this._http = new HttpClient();
this._http.configure(config => {
config
.withBaseUrl(url)
.withInterceptor({
request(request) {
console.log(`Requesting ${request.method} ${request.url}`);
return request; // you can return a modified Request, or you can short-circuit the request by returning a Response
},
response(response) {
console.log(`Received ${response.status} ${response.url}`);
return response; // you can return a modified Response
}
})
.withDefaults({
'mode' : 'cors',
headers: {
'Authorization': `Bearer ${localStorage.getItem('access_token')}`
}
})
.useStandardConfiguration();
});
}
Вот что мы видим в Chrome. Я выставляю заголовки, которые хочу.
aurelia-http-client
, то, я подозреваю, вы сможете их увидеть. Но в нем могут отсутствовать другие функции, которые вам нужны. - person Tom   schedule 29.09.2017