Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http Response headers incomplete ? #13226

Closed
vfedoriv opened this issue Dec 4, 2016 · 5 comments
Closed

http Response headers incomplete ? #13226

vfedoriv opened this issue Dec 4, 2016 · 5 comments

Comments

@vfedoriv
Copy link

vfedoriv commented Dec 4, 2016

I'm submitting a ... (check one with "x")

[X ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

If I get Response from http request, response.headers contain only "application/json; charset=utf-8"

import { Component, OnInit } from '@angular/core';
import {Http} from "@angular/http";

@Component({
  selector: 'app-simple-test',
  templateUrl: './simple-test.component.html',
  styleUrls: ['./simple-test.component.css']
})
export class SimpleTestComponent implements OnInit {

  private test_url = "http://www.mocky.io/v2/5843ecc6100000da1c1a5734";
  private output_string ="";

  constructor(private http: Http) { }

  ngOnInit() {
    this.http.get(this.test_url)
      .subscribe(response => {
        this.output_string = "response: " + response + "; response headers values: " + response.headers.values();
      }, (error) => {
        console.log(error);
      });
  }
}

headers_test

Expected behavior
Expected: get list all headers from http response

Minimal reproduction of the problem with instructions

I create link with REST response there: http://www.mocky.io/v2/5843ecc6100000da1c1a5734
(with added headers "Access-Control-Allow-Origin: *" and "Errors: error message")
and create test
Plunker link: http://plnkr.co/edit/vJD4Zuo0MxKAdb4nA1Xl?p=preview

What is the motivation / use case for changing the behavior?

parsing response headers from backend application

Please tell us about your environment:

Win10 64bit, npm 4.0.3

  • Angular version: 2.2.X
  • Browser: [ Chrome 54 | Firefox 50 ]
  • Language: [TypeScript 2.0.10]

  • Node (for AoT issues): node --version = 7.2.0

@DzmitryShylovich
Copy link
Contributor

DzmitryShylovich commented Dec 4, 2016

Can u send the same request using plain xhr and compare results?

See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers

@vfedoriv
Copy link
Author

vfedoriv commented Dec 4, 2016

    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'http://www.mocky.io/v2/5843ecc6100000da1c1a5734', false);
    xhr.send();
    this.output_string2 = "XMLHttpRequest().getAllResponseHeaders() " + xhr.getAllResponseHeaders();

Result: XMLHttpRequest().getAllResponseHeaders() Content-Type: application/json; charset=utf-8

But why ???

@vfedoriv
Copy link
Author

vfedoriv commented Dec 4, 2016

Oh, I found problem: it's CORS.
Need add "Access-Control-Expose-Headers" with list of headers in response headers.

@vfedoriv
Copy link
Author

vfedoriv commented Dec 4, 2016

Thanks for you question - it's helped me to find answer.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants