-
Notifications
You must be signed in to change notification settings - Fork 19
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
Interceptor #2042
Interceptor #2042
Changes from 4 commits
674bdeb
9f213e4
76fe434
0ee11f2
64bcf2b
f68f4c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { HttpHandler, HttpInterceptor, HttpRequest } from "@angular/common/http"; | ||
import { Injectable } from "@angular/core"; | ||
|
||
@Injectable() | ||
export class HttpContentTypeHeaderInterceptor implements HttpInterceptor { | ||
construct () { | ||
|
||
} | ||
|
||
intercept(req:HttpRequest<any>, next: HttpHandler) { | ||
var method = req.method | ||
var urlWithParams = req.urlWithParams | ||
// If the request contains a content type, be sure to set the encoding to utf-8 | ||
if(['POST', 'PUT'].includes(method)) { | ||
var clonedRequest; | ||
if(urlWithParams == '/signin/auth.json') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this header excepcion seems to be require for Maybe we can declare a class level atribute like
And check if a route is in the array
|
||
clonedRequest = req.clone({ | ||
headers: req.headers.set('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8') | ||
}); | ||
} else { | ||
clonedRequest = req.clone({ | ||
headers: req.headers.set('Content-Type', 'application/json;charset=utf-8') | ||
}); | ||
} | ||
|
||
console.log("-------------------------------------------------------------------------------------") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this logs be remove? |
||
console.log(method) | ||
console.log(urlWithParams) | ||
console.log(clonedRequest.headers) | ||
console.log("-------------------------------------------------------------------------------------") | ||
return next.handle(clonedRequest); | ||
} | ||
console.log('Nothing changed for ' + method + ' - ' + urlWithParams); | ||
// Nothing changed, continue using the same request object | ||
return next.handle(req); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to add
PATCH
in the future.NO a change we need right now