I need to find out if a URL can be previewed in an iFrame (some users will want this feature - and may have a url set to allow displaying in an iFrame). I want to check for an X-Frame-Options value of Deny or SameOrigin
I found a lot of examples of making an http client get request to api's. But I am having trouble finding an example for my specific use case.
I just need to return the headers after requesting a url. Below is one example of the many I have tried.
How is the X-Frame-Options value fetched from a URL, client-side, using Angular?
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class WebUrlPreviewService {
private requestHeaders: HttpHeaders;
constructor(private http: HttpClient) {
this.requestHeaders = new HttpHeaders();
this.requestHeaders.append('Content-Type', 'application/json');
this.requestHeaders.append('Accept', 'application/json');
}
getResponseHeaders(url: string):Observable<HttpResponse<HttpHeaders>> {
return this.http.get<HttpHeaders>(url, {observe: 'response'});
}
}
from How to get the X-Frame-Options value from a website URL's Response Headers in Angular 7?
No comments:
Post a Comment