404 header – HTTP 1.0 or 1.1?

In PHP you should probably use: header( $_SERVER[‘SERVER_PROTOCOL’].” 404 Not Found”, true ); or even better header( $_ENV[‘SERVER_PROTOCOL’].” 404 Not Found”, true ); (if supported) and thus leave it to the web-server which protocol to use. Actually, if you pass the status code as 3rd parameter, you can pass whatever you want in the 1st … Read more

Angular 2 Basic Authentication not working

Simplified version to add custom headers to your request: import {Injectable} from ‘@angular/core’; import {Http, Headers} from ‘@angular/http’; @Injectable() export class ApiService { constructor(private _http: Http) {} call(url): Observable<any> { let username: string = ‘username’; let password: string = ‘password’; let headers: Headers = new Headers(); headers.append(“Authorization”, “Basic ” + btoa(username + “:” + password)); … Read more

c++ template and header files [duplicate]

Headers. It’s because templates are instantiated at compile-time, not link-time, and different translation units (roughly equivalent to your .cpp files) only “know about” each other at link-time. Headers tend to be widely “known about” at compile-time because you #include them in any translation unit that needs them. Read https://isocpp.org/wiki/faq/templates for more.

C++ class header files organization

Some general guidelines: Pair up your interfaces with implementations. If you have foo.cxx, everything defined in there had better be declared in foo.h. Ensure that every header file #includes all other necessary headers or forward-declarations necessary for independent compilation. Resist the temptation to create an “everything” header. They’re always trouble down the road. Put a … Read more

Define constant variables in C++ header

You could simply define a series of const ints in a header file: // Constants.h #if !defined(MYLIB_CONSTANTS_H) #define MYLIB_CONSTANTS_H 1 const int a = 100; const int b = 0x7f; #endif This works because in C++ a name at namespace scope (including the global namespace) that is explicitly declared const and not explicitly declared extern … Read more

Adding header to all request with Retrofit 2

OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request().newBuilder().addHeader(“parameter”, “value”).build(); return chain.proceed(request); } }); Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create()).baseUrl(url).client(httpClient.build()).build();