Skip to content

http gzip support missing #1314

Closed
Closed

Description

@NathanaelA

The http module in nativescript apparently doesn't support basic things like gzip (at least on Android). I have a server that by default is sending a gzipped response (to save major bandwidth as the data is rather large) and of course then the http module will die a horribile death and throw a Java EOF error.

This is actually something that is very surprising that it is totally broken in NS as anything mobile we want to save the amount of data being transferred. So by default we should be supporting http data compression.

If anyone else runs into this issue; you can send the header: accept-encoding: identity which will force it to be a text based uncompressed stream protocol.

Activity

  1. added this to the milestone on Jan 4, 2016
  2. atanasovg commented on Jan 5, 2016

    @atanasovg
    Contributor

    We may research whether the okhttp library for Android already handles this. Relates to NativeScript/android#209. Probably a custom http plugin that enables okhttp would be a viable solution.

  3. modified the milestones: , 1.6.0 on Jan 5, 2016
  4. valentinstoychev commented on Jan 6, 2016

    @valentinstoychev

    Yes - we should check this as and provide a recommended way for consumption of "zipped" http content in NativeScript as this really will increase the perf of the app. cc: @enchev

  5. enchev commented on Jan 14, 2016

    @enchev
    Contributor

    Technically you/we can add support even know in our JavaScript wrapper or simply in the application using this approach however in this case unzipping will be in the UI thread.

    We plan to move our Android HTTP implementation from the runtime to separate plugin similar to widgets where we can add this functionality and our modules will depend on the new Async module similar again to widgets.

    What do you think about this plan? :)

  6. modified the milestone: on Feb 24, 2016
  7. jacargentina commented on Feb 20, 2017

    @jacargentina

    @enchev On iOS i have no problem with the gzip response. Seems to be related only to the Android. Any news on this?

  8. mshanak commented on Mar 12, 2017

    @mshanak

    you can use nativescript http with angular , following example:

    first import http serves in the top of the service component
    var http = require("http");

    in the sevice.ts file ,you need to convert the http promise to observable .

    //GET Example
    	getList(): Observable<News[]> {
    		return Observable.fromPromise(
    					**http.getJSON(serverConfig.apiUrl+"news")**
    				).map(function(res:any) {
    					console.log('finished sendign request'); 
    					return res as News[] 
    				} );
    
    	}
    
    
    //POST EXAMPLE
    
    submitFormData(data): Observable<Forms> {
    		let url:string=serverConfig.apiUrl+"forms/";
    		let headers:any = { 'Content-Type': 'application/json', 'Authorization': 'Bearer '+this.appSettings.getString("access_token")};
    		let req:any={
    			url:url,
    			method: "post",
    			headers:headers,
    			content: JSON.stringify(data)
    		};
    
    		return Observable.fromPromise(
    					http.getJSON(req)
    				).map(function(res:any) {
    					return res as Forms 
    				} );
     	}
    
    

    then you can subscribe to the observeable as you used befor,

    		this.newsService.getList().subscribe((res) => {
    			this.news= res;
    		});
    

    Note : now you can remove the import statment of angular http since its not needed

  9. dzfweb commented on Apr 6, 2017

    @dzfweb

    @mshanak still not working, even using your sample code.
    SyntaxError: Unexpected token < in JSON at position 0

  10. mshanak commented on Apr 6, 2017

    @mshanak

    This is my news.service.ts

    
    import { Injectable } from '@angular/core';
    var http = require("http");
    import { Observable } from 'rxjs/Observable';
    import 'rxjs/add/operator/map';
    import { News } from './news.model';
    import {serverConfig} from '../../../config/api'
    @Injectable()
    export class NewsService {
    
    	constructor() { }
    
    	getList(): Observable<News[]> {
    		return Observable.fromPromise(
    					http.getJSON(serverConfig.apiUrl+"news")
    				).map(function(res:any) {
    					console.log('finished sendign request'); 
    					return res.data as News[] 
    				} );
    
    	}
    
    	getOne(id:number): Observable<News> { 
    		return Observable.fromPromise(
    					http.getJSON(serverConfig.apiUrl+"news/"+id)
    				).map(function(res:any) {
    					console.log('finished sendign request'); 
    					return res as News
    				} );
    
    	}
    
    } 
    

    and this is how i consume this service

    
    this.newsService.getList().subscribe((res) => {
    			this.news= res;	
    		});
    

    it should work

  11. NathanaelA commented on Jul 12, 2018

    @NathanaelA
    Author
  12. added this to the 4.2 milestone on Aug 6, 2018
  13. NickIliev commented on Aug 6, 2018

    @NickIliev
    Contributor
  14. ghost removed on Aug 6, 2018
  15. lock commented on Aug 26, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  16. locked and limited conversation to collaborators on Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions